class (object): def pathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: List[List[int]] """ ret = [] self.helper(root, [], sum, ret) return ret def helper(self, root, cur, sum, ret): if not root: return if not root.left and not root.right and sum - root.val == 0: cur.append(root.val) ret.append(cur[:]) cur.pop() return for node in [root.left, root.right]: sum -= root.val cur.append(root.val) self.helper(node, cur, sum, ret) sum += root.val cur.pop()
|
近期评论