Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
(压平二叉树)
Example:
1. 递归
递归压平子树,然后将左子树放在右子树上,并将左子树置为None。然后找到叶子节点将原来的右子树连接在后面。具体实现过程如下:
1 | # Definition for a binary tree node. |
Given a binary tree, flatten it to a linked list in-place.
(压平二叉树)
Example:
递归压平子树,然后将左子树放在右子树上,并将左子树置为None。然后找到叶子节点将原来的右子树连接在后面。具体实现过程如下:
1 | # Definition for a binary tree node. |