L453 Flatten Binary Tree to Linked List
Last updated
Was this helpful?
Last updated
Was this helpful?
Flatten a binary tree to a fake "linked list" in pre-order traversal.
Here we use the_right_pointer in TreeNode as the_next_pointer in ListNode.
Don't forget to mark the left child of each node to null. Or you will get Time Limit Exceeded or Memory Limit Exceeded.
Example
Do it in-place without any extra memory.
这题变相考了非递归的pre order traversal。