Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 1.46 KB

0114-flatten-binary-tree-to-linked-list.adoc

File metadata and controls

78 lines (60 loc) · 1.46 KB

114. Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.

For example, given the following tree:

    1
   / \
  2   5
 / \   \
3   4   6

The flattened tree should look like:

1
 \
  2
   \
    3
     \
      4
       \
        5
         \
          6

这道题本质上来讲可以说是要做一个先根遍历。但是,却可以将这个过程逆向过来,从底向上建立起关联。不可谓不精巧。

思考题:看题解中,可以逐级将左树并入到右树。尝试一下。

参考资料

Given a binary tree, flatten it to a linked list in-place.

For example, given the following tree:

    1
   / \
  2   5
 / \   \
3   4   6

The flattened tree should look like:

1
 \
  2
   \
    3
     \
      4
       \
        5
         \
          6
link:{sourcedir}/_0114_FlattenBinaryTreeToLinkedList.java[role=include]