Skip to content

Latest commit

 

History

History
104 lines (69 loc) · 2.27 KB

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

File metadata and controls

104 lines (69 loc) · 2.27 KB

114. Flatten Binary Tree to Linked List

{leetcode}/problems/flatten-binary-tree-to-linked-list/[LeetCode - 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

思路分析

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

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

{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
{image_attr}
link:{sourcedir}/_0114_FlattenBinaryTreeToLinkedList.java[role=include]
link:{sourcedir}/_0114_FlattenBinaryTreeToLinkedList_2.java[role=include]
link:{sourcedir}/_0114_FlattenBinaryTreeToLinkedList_3.java[role=include]

思考题

如何使用递归来实现?

link:{sourcedir}/_0114_FlattenBinaryTreeToLinkedList_3rec.java[role=include]