# 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(root,temp): if root : temp+=str(root.val) if not root.left and not root.right: res.append(temp) else: temp+='->' dfs(root.left,temp) dfs(root.right,temp) dfs(root,'') return res