Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Cs Summary Reflection
提交
1c440bd2
C
Cs Summary Reflection
项目概览
梦境迷离
/
Cs Summary Reflection
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
1c440bd2
编写于
6月 11, 2020
作者:
L
laozhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add python 1305 and python 814
上级
38d14916
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
0 deletion
+68
-0
python-leetcode/README.md
python-leetcode/README.md
+2
-0
python-leetcode/solution/tree/leetcode_1305_.py
python-leetcode/solution/tree/leetcode_1305_.py
+43
-0
python-leetcode/solution/tree/leetcode_814_.py
python-leetcode/solution/tree/leetcode_814_.py
+23
-0
未找到文件。
python-leetcode/README.md
浏览文件 @
1c440bd2
...
...
@@ -45,6 +45,8 @@
31.
[
最大二叉树
](
./solution/tree/leetcode_654_.py
)
32.
[
层数最深叶子节点的和
](
./solution/tree/leetcode_1302_.py
)
33.
[
祖父节点值为偶数的节点和
](
./solution/tree/leetcode_1315_.py
)
34.
[
两棵二叉搜索树中的所有元素
](
./solution/tree/leetcode_1305_.py
)
35.
[
二叉树剪枝
](
./solution/tree/leetcode_814_.py
)
...
...
python-leetcode/solution/tree/leetcode_1305_.py
0 → 100644
浏览文件 @
1c440bd2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
1305. 两棵二叉搜索树中的所有元素
"""
from
typing
import
List
from
solution
import
TreeNode
class
Solution
:
def
getAllElements
(
self
,
root1
:
TreeNode
,
root2
:
TreeNode
)
->
List
[
int
]:
list1
=
[]
list2
=
[]
list
=
[]
def
helper
(
root
:
TreeNode
,
res
:
List
[
int
]):
if
root
:
helper
(
root
.
left
,
res
)
res
.
append
(
root
.
val
)
helper
(
root
.
right
,
res
)
helper
(
root1
,
list1
)
helper
(
root2
,
list2
)
var1
=
0
var2
=
0
l1
=
len
(
list1
)
l2
=
len
(
list2
)
while
var1
<
l1
and
var2
<
l2
:
if
list1
[
var1
]
>
list2
[
var2
]:
list
.
append
(
list2
[
var2
])
var2
+=
1
else
:
list
.
append
(
list1
[
var1
])
var1
+=
1
if
var1
<
l1
:
return
list
+
list1
[
var1
:
l1
]
if
var2
<
l2
:
return
list
+
list2
[
var2
:
l2
]
return
list
python-leetcode/solution/tree/leetcode_814_.py
0 → 100644
浏览文件 @
1c440bd2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
814. 二叉树剪枝
"""
from
solution
import
TreeNode
class
Solution
:
def
pruneTree
(
self
,
root
:
TreeNode
)
->
TreeNode
:
def
helper
(
root
:
TreeNode
)
->
TreeNode
:
if
root
:
helper
(
root
.
left
)
helper
(
root
.
right
)
if
root
:
if
root
.
left
and
root
.
left
.
val
==
0
and
not
root
.
left
.
left
and
not
root
.
left
.
right
:
root
.
left
=
None
if
root
.
right
and
root
.
right
.
val
==
0
and
not
root
.
right
.
right
and
not
root
.
right
.
left
:
root
.
right
=
None
helper
(
root
)
return
root
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录