# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def binaryTreePaths(self, root: TreeNode) -> List[str]:
res = []
def dfs(node, path):
if node is None:
return
path.append(str(node.val))
if node.left is None and node.right is None:
res.append('->'.join(path))
else:
dfs(node.left, path)
dfs(node.right, path)
path.pop()
dfs(root, [])
return res