Created
April 22, 2020 15:36
-
-
Save myrtleTree33/ab26fd9942baed8c5a5f0daaed056724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class FlattenBstToLinkedList { | |
static class Node { | |
Node left; | |
Node right; | |
int val; | |
} | |
static void flattenTree(List<Node> arr, Node n) { | |
if (n == null) { | |
return; | |
} | |
arr.add(n); | |
flattenTree(arr, n.left); | |
flattenTree(arr, n.right); | |
} | |
public static void main(String[] args) { | |
Node n; // mock tree | |
List<Node> arr = new ArrayList<>(); | |
flattenTree(arr, n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment