Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8_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
杨鹏
8_homework
Commits
7455f6eb
Commit
7455f6eb
authored
Jan 22, 2019
by
yangpengflag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init commit
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
maxDepth.py
+47
-0
No files found.
maxDepth.py
0 → 100644
View file @
7455f6eb
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class
Solution
(
object
):
"""
:type root: TreeNode
:rtype: int
"""
def
__init__
(
self
,
x
):
self
.
val
=
x
self
.
left
=
9
self
.
right
=
20
def
maxDepth
(
self
,
root
):
if
root
is
None
:
return
0
else
:
leftDepth
=
self
.
maxDepth
(
root
.
left
)
+
1
rightDepth
=
self
.
maxDepth
(
root
.
right
)
+
1
return
max
(
leftDepth
,
rightDepth
)
if
__name__
==
"__main__"
:
l1
=
[
3
,
9
,
20
,
''
,
''
,
15
,
7
]
l2
=
[
3
,
9
,
20
,
''
,
''
,
15
,
7
,
10
,
4
,
6
,
3
]
solution
=
Solution
(
3
)
print
(
solution
.
maxDepth
(
l1
))
# print(solution.maxDepth(l))
#
# l = [3,9,20,'','',15,7,10,4,6,3]
# print(solution.maxDepth(l))
\ No newline at end of file
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