Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
Solution: Note that the requirement is to do it in-place. The key is to use pre-order traversal (root->left->right). Each time, we linked the left subtree and the right subtree.
Recursive: Iterative:
Solution: Note that the requirement is to do it in-place. The key is to use pre-order traversal (root->left->right). Each time, we linked the left subtree and the right subtree.
Recursive: Iterative:
Comments
Post a Comment