Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Cs Summary Reflection
提交
c71a9c07
C
Cs Summary Reflection
项目概览
梦境迷离
/
Cs Summary Reflection
大约 1 年 前同步成功
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cs Summary Reflection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c71a9c07
编写于
7月 04, 2020
作者:
梦境迷离
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:jxnu-liguobin/cs-summary-reflection
上级
bab133d0
2684ba89
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
0 deletion
+43
-0
python-leetcode/README.md
python-leetcode/README.md
+1
-0
python-leetcode/solution/tree/leetcode_117_.py
python-leetcode/solution/tree/leetcode_117_.py
+42
-0
未找到文件。
python-leetcode/README.md
浏览文件 @
c71a9c07
...
...
@@ -66,6 +66,7 @@
52.
[
二叉搜索树的范围和
](
./solution/tree/leetcode_938_.py
)
53.
[
路径总和 II
](
./solution/tree/leetcode_113_.py
)
54.
[
填充每个节点的下一个右侧节点指针
](
./solution/tree/leetcode_116_.py
)
55.
[
填充每个节点的下一个右侧节点指针 II
](
./solution/tree/leetcode_117_.py
)
...
...
python-leetcode/solution/tree/leetcode_117_.py
0 → 100644
浏览文件 @
c71a9c07
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
117. 填充每个节点的下一个右侧节点指针 II
"""
class
Solution
:
"""
0.分三种情况
1.如果根节点包含左右子节点则通过root.left.next = root.right连接
2.根节点只有左节点的情况则找到同层节点中离此节点最近的一个进行相连即:root.left.next = getNextNode(root.next)
3.根节点只包含右节点的情况则找到同层节点中离此节点最近的一个进行相连即:root.right.next = getNextNode(root.next)
4.重复1进行dfs递归
5.注意:递归时要先递归右子树,否则上级节点next关系没建好,下级无法成功getNextNode
"""
def
connect
(
self
,
root
:
'Node'
)
->
'Node'
:
def
getNextNode
(
root
:
Node
):
if
not
root
:
return
None
if
root
.
left
:
return
root
.
left
if
root
.
right
:
return
root
.
right
if
root
.
next
:
return
getNextNode
(
root
.
next
)
def
dfs
(
root
:
Node
):
if
root
:
if
root
.
left
and
root
.
right
:
root
.
left
.
next
=
root
.
right
if
root
.
left
and
not
root
.
right
:
root
.
left
.
next
=
getNextNode
(
root
.
next
)
if
root
.
right
:
root
.
right
.
next
=
getNextNode
(
root
.
next
)
dfs
(
root
.
right
)
dfs
(
root
.
left
)
dfs
(
root
)
return
root
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录