Skip to content

Commit a760daa

Browse files
committed
Time: 59 ms (5.20%), Space: 16.3 MB (89.16%) - LeetHub
1 parent 1990bfd commit a760daa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]:
3+
ans = []
4+
def solve(root, s):
5+
s += str(root.val)
6+
if not root.right and not root.left:
7+
ans.append(s)
8+
return
9+
if root.right:
10+
solve(root.right, s+"->")
11+
if root.left:
12+
solve(root.left, s+"->")
13+
solve(root, "")
14+
return ans

0 commit comments

Comments
 (0)