Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1_homework_安晓东
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
安晓东
1_homework_安晓东
Commits
cc315b06
Commit
cc315b06
authored
Jan 23, 2019
by
“安晓东”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
第八次作业-二叉树
parent
44fbd452
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
lession_8/Solution.py
+14
-0
lession_8/__init__.py
+19
-0
No files found.
lession_8/Solution.py
0 → 100644
View file @
cc315b06
# 二叉树的最大深度
# 给定一个二叉树,找出其最大深度。
# 二叉树的深度为根节点到最远叶子节点的距离。
# 如果二叉树为空,则深度为0
# 如果不为空,分别求左子树的深度和右子树的深度,取最大的再加1
class
Solution
:
def
maxDepth
(
self
,
root
):
if
root
==
None
:
return
0
else
:
return
max
(
self
.
maxDepth
(
root
.
left
),
self
.
maxDepth
(
root
.
right
))
+
1
lession_8/__init__.py
0 → 100644
View file @
cc315b06
# a = [1,3,5,6]
# for i in a:
# s = a.index(i)
# print(str(i)+'====='+str(s))
class
Solution
(
object
):
def
__init__
(
self
,
lis
):
self
.
lis
=
lis
def
deleteNode
(
self
,
node
):
for
i
in
self
.
lis
:
if
i
==
node
:
self
.
lis
.
remove
(
node
)
return
self
.
lis
if
__name__
==
'__main__'
:
str
=
[
1
,
3
,
4
,
5
,
2
,
6
]
s
=
Solution
(
str
)
print
(
s
.
deleteNode
(
6
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment