未验证 提交 ab916b84 编写于 作者: K Keqi Huang 提交者: GitHub

Update 0114._flatten_binary_tree_to_linked_list.md

上级 22ba82b6
### 114. Flatten Binary Tree to Linked List
# 114. Flatten Binary Tree to Linked List
题目:
<https://leetcode.com/problems/flatten-binary-tree-to-linked-list/>
**<font color=red>难度: Medium</font>**
## 刷题内容
难度:
> 原题连接
Medium
* https://leetcode.com/problems/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
```
## 解题方案
> 思路 1
******- 时间复杂度: O(N)******- 空间复杂度: O(N)******
这道题看了hint,说每个node的右节点都是相应先序遍历中它的下一个节点。
所以我的思路是先把先序遍历的node顺序搞出来,然后对于这里面的每一个节点,只需要做两个操作:
......@@ -41,6 +73,9 @@ class Solution(object):
```
beat 40.67%
> 思路 2
******- 时间复杂度: O(N)******- 空间复杂度: O(N)******
另外一种解法:
1. copy the left and right subtree
2. then cut root’s left subtree
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册