Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
awesome-algorithm
提交
ab916b84
A
awesome-algorithm
项目概览
OpenDocCN
/
awesome-algorithm
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
awesome-algorithm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
ab916b84
编写于
2月 26, 2019
作者:
K
Keqi Huang
提交者:
GitHub
2月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update 0114._flatten_binary_tree_to_linked_list.md
上级
22ba82b6
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
40 addition
and
5 deletion
+40
-5
docs/Leetcode_Solutions/Python/0114._flatten_binary_tree_to_linked_list.md
...utions/Python/0114._flatten_binary_tree_to_linked_list.md
+40
-5
未找到文件。
docs/Leetcode_Solutions/Python/0114._flatten_binary_tree_to_linked_list.md
浏览文件 @
ab916b84
#
##
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录