forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0257.py
More file actions
23 lines (19 loc) · 636 Bytes
/
0257.py
File metadata and controls
23 lines (19 loc) · 636 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def binaryTreePaths(self, root):
"""
:type root: TreeNode
:rtype: List[str]
"""
result = list()
if root == None:
return result
if root.left == None and root.right == None:
result.append(str(root.val))
return result
left = self.binaryTreePaths(root.left)
for i in range(len(left)):
result.append(str(root.val) + '->' + left[i])
right = self.binaryTreePaths(root.right)
for i in range(len(right)):
result.append(str(root.val) + '->' + right[i])
return result