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:

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs