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: 11 if 0 == sum: 12 ans.append(tmp[::]) 13 tmp.pop() 14 helper(root,sum) 15 return ans
原文:https://www.cnblogs.com/lj95/p/14297264.html