1 class Solution: 2 def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: 3 ans,tmp = [],[] 4 def helper(root,sum): 5 if not root:return 6 tmp.append(root.val) 7 sum -= root.val 8 helper(root.left,sum) 9 helper(root.right,sum) 10 if not root.left and not root.right and 0 == sum: 11 ans.append(tmp[:]) 12 tmp.pop() 13 helper(root,sum) 14 return ans 15