FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-algorithms/python/binary_tree_paths.py at master · anishLearnsToCode/leetcode-algorithms · GitHub
anishLearnsToCode
/
leetcode-algorithms
Public
Notifications
You must be signed in to change notification settings
Fork
17
Star
98
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-algorithms
/
python
/
binary_tree_paths.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (22 loc) · 909 Bytes
Breadcrumbs
leetcode-algorithms
/
python
/
binary_tree_paths.py
Copy path
File metadata and controls
28 lines (22 loc) · 909 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
from
typing
import
List
# Definition for a binary tree node.
class
TreeNode
:
def
__init__
(
self
,
val
=
0
,
left
=
None
,
right
=
None
):
self
.
val
=
val
self
.
left
=
left
self
.
right
=
right
class
Solution
:
def
is_leaf_node
(
self
,
root
:
TreeNode
)
->
bool
:
return
root
.
left
is
None
and
root
.
right
is
None
def
binary_tree_paths
(
self
,
root
:
TreeNode
,
current_path
:
str
,
results
:
List
[
str
]):
if
root
is
None
:
return
if
self
.
is_leaf_node
(
root
):
results
.
append
(
f'
{
current_path
}
->
{
root
.
val
}
'
[
2
:])
return
self
.
binary_tree_paths
(
root
.
left
,
f'
{
current_path
}
->
{
root
.
val
}
'
,
results
)
self
.
binary_tree_paths
(
root
.
right
,
f'
{
current_path
}
->
{
root
.
val
}
'
,
results
)
def
binaryTreePaths
(
self
,
root
:
TreeNode
)
->
List
[
str
]:
result
=
[]
self
.
binary_tree_paths
(
root
,
''
,
results
=
result
)
return
result
Back
|
FazBrowse Home
|
New Git URL