leetcode -- Path Sum II --- 重点,未理解

来源:互联网 发布:mac bilibili直播端 编辑:程序博客网 时间:2024/06/05 06:13

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

没有太理解。要再看看

参考:
http://www.cnblogs.com/zuoyuan/p/3752503.html

自己重写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
0 0