Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save myrtleTree33/ab26fd9942baed8c5a5f0daaed056724 to your computer and use it in GitHub Desktop.
Save myrtleTree33/ab26fd9942baed8c5a5f0daaed056724 to your computer and use it in GitHub Desktop.
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