# 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 binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]:
ret = []
tmp = []
def dfs(x):
if not x: return
tmp.append(str(x.val))
if not x.left and not x.right:
ret.append('->'.join(tmp))
dfs(x.left)
dfs(x.right)
tmp.pop()
dfs(root)
return ret