题目描述: 参考后的提交: class Solution(object): def pathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: List[List[int]] """ r = [] l = [] if not root: return r def path(root, l , sum): if not root: return l.append…
题目描述: 第一次提交: class Solution(object): def hasPathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ if not root : return False if sum - root.val == 0 and not root.left and not root.right: return Tru…
题目描述: 方法一: class Solution: def combinationSum(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ ans=[] n=len(candidates) if candidates==[]: return [] for i in range(n): i…
题目描述: 第一次提交:参考113-路径总和② class Solution: def binaryTreePaths(self, root: TreeNode) -> List[str]: r = [] if not root: return r l = "" def path(root, l): if not root: return l += str(root.val) if not root.left and not root.right: r.append(l) l +…