https://leetcode.com/problems/path-sum-ii/

没有太理解。要再看看


自己重写code

class Solution(object):

    def dfs(self, root, target, valuelist, res):
        if root.left == None and root.right == None:
            if root.val == target:
                res.append(valuelist + [root.val])
        else:
            if root.left:
                self.dfs(root.left, target - root.val, valuelist + [root.val], res)
            if root.right:
                self.dfs(root.right, target - root.val, valuelist + [root.val], res)

    def pathSum(self, root, sum):
        """
        :type root: TreeNode
        :type sum: int
        :rtype: List[List[int]]
        """
        if not root: return []
        res = []
        self.dfs(root, sum, [], res)
        return res