114. Flatten Binary Tree to Linked List

# Medium

很有意思的一道题,思路其实不难,主要是recursive的思想,跟Tree没有太大关系。

Solution:

  1. transform root.right to temp.

  2. flat root.left then transfer root.right.

  3. assign root to root2, let root2 goes to the bottom of the tree.

  4. link root2 with flat(temp).

  5. return root.

  6. stop condition: if root = NULL, return imediately.

Don't forget to return real root finally.

Last updated

Was this helpful?