# 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: TreeNode) -> List[str]:
def backtrack(root,path):
if root is None:
return
path += str(root.val)
if root.left is None and root.right is None:
res.append(path)
else:
path += '->'
backtrack(root.left,path)
backtrack(root.right,path)
res = []
backtrack(root,'')
return res