Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Cs Summary Reflection
提交
81ad6513
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 搜索 >>
提交
81ad6513
编写于
6月 14, 2020
作者:
L
laozhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add python 1325 and python 230
上级
db53f164
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
0 deletion
+54
-0
python-leetcode/README.md
python-leetcode/README.md
+2
-0
python-leetcode/solution/tree/leetcode_1325_.py
python-leetcode/solution/tree/leetcode_1325_.py
+27
-0
python-leetcode/solution/tree/leetcode_230_.py
python-leetcode/solution/tree/leetcode_230_.py
+25
-0
未找到文件。
python-leetcode/README.md
浏览文件 @
81ad6513
...
...
@@ -51,6 +51,8 @@
37.
[
二叉搜索树迭代器
](
./solution/tree/leetcode_173_.py
)
38.
[
二叉树的中序遍历
](
./solution/tree/leetcode_94_.py
)
39.
[
先序遍历构造二叉树
](
./solution/tree/leetcode_1008_.py
)
40.
[
二叉搜索树中第K小的元素
](
./solution/tree/leetcode_230_.py
)
41.
[
删除给定值的叶子节点
](
./solution/tree/leetcode_1325_.py
)
...
...
python-leetcode/solution/tree/leetcode_1325_.py
0 → 100644
浏览文件 @
81ad6513
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
1325. 删除给定值的叶子节点
"""
from
solution
import
TreeNode
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class
Solution
:
def
removeLeafNodes
(
self
,
root
:
TreeNode
,
target
:
int
)
->
TreeNode
:
if
not
root
:
return
None
root
.
left
=
self
.
removeLeafNodes
(
root
.
left
,
target
)
root
.
right
=
self
.
removeLeafNodes
(
root
.
right
,
target
)
if
not
root
.
left
and
not
root
.
right
and
root
.
val
==
target
:
return
None
else
:
return
root
python-leetcode/solution/tree/leetcode_230_.py
0 → 100644
浏览文件 @
81ad6513
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
230. 二叉搜索树中第K小的元素
"""
from
solution
import
TreeNode
class
Solution
:
def
kthSmallest
(
self
,
root
:
TreeNode
,
k
:
int
)
->
int
:
count
=
0
min
=
0
def
helper
(
root
:
TreeNode
,
k
:
int
):
nonlocal
count
,
min
if
root
:
helper
(
root
.
left
,
k
)
count
+=
1
if
count
==
k
:
min
=
root
.
val
helper
(
root
.
right
,
k
)
helper
(
root
,
k
)
return
min
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录