114 Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
For example, Given
1
/ \
2 5
/ \ \
3 4 6The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6// runs on my comp
Approach:
Create a LL through traversal, and then append to root.
Technically O(1) space, since I make to delete the left subtree.
O(n), since I just append to root
Working O(N) space trivial solution
Last updated
Was this helpful?