-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlintcode_480.py
More file actions
28 lines (27 loc) · 790 Bytes
/
lintcode_480.py
File metadata and controls
28 lines (27 loc) · 790 Bytes
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
"""
Definition of TreeNode:
class TreeNode:
def __init__(self, val):
self.val = val
self.left, self.right = None, None
"""
class Solution:
"""
@param root: the root of the binary tree
@return: all root-to-leaf paths
"""
def binaryTreePaths(self, root):
# write your code here
if root == None:
return []
res = []
if root.left == None and root.right == None:
res.append(str(root.val))
return res
left_res = self.binaryTreePaths(root.left)
right_res = self.binaryTreePaths(root.right)
for item in left_res:
res.append(str(root.val) + "->" + item)
for item in right_res:
res.append(str(root.val) + "->" + item)
return res