FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-python/algorithms/tree/deepest_left.py at master · ivan1911/algorithms-python · GitHub
ivan1911
/
algorithms-python
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms-python
/
algorithms
/
tree
/
deepest_left.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (36 loc) · 985 Bytes
Breadcrumbs
algorithms-python
/
algorithms
/
tree
/
deepest_left.py
Copy path
File metadata and controls
46 lines (36 loc) · 985 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Given a binary tree, find the deepest node
# that is the left child of its parent node.
# Example:
# 1
# / \
# 2 3
# / \ \
# 4 5 6
# \
# 7
# should return 4.
from
tree
.
tree
import
TreeNode
class
DeepestLeft
:
def
__init__
(
self
):
self
.
depth
=
0
self
.
Node
=
None
def
find_deepest_left
(
root
,
is_left
,
depth
,
res
):
if
not
root
:
return
if
is_left
and
depth
>
res
.
depth
:
res
.
depth
=
depth
res
.
Node
=
root
find_deepest_left
(
root
.
left
,
True
,
depth
+
1
,
res
)
find_deepest_left
(
root
.
right
,
False
,
depth
+
1
,
res
)
if
__name__
==
'__main__'
:
root
=
TreeNode
(
1
)
root
.
left
=
TreeNode
(
2
)
root
.
right
=
TreeNode
(
3
)
root
.
left
.
left
=
TreeNode
(
4
)
root
.
left
.
right
=
TreeNode
(
5
)
root
.
right
.
right
=
TreeNode
(
6
)
root
.
right
.
right
.
right
=
TreeNode
(
7
)
res
=
DeepestLeft
()
find_deepest_left
(
root
,
True
,
1
,
res
)
if
res
.
Node
:
print
(
res
.
Node
.
val
)
Back
|
FazBrowse Home
|
New Git URL