left= False right = False ifNone != root.left: new_path = path[:] new_path.append(root.val) left = self.doPathSum(root.left, total + root.val, sum, new_path) ifNone != root.right: new_path = path[:] new_path.append(root.val) right = self.doPathSum(root.right, total + root.val, sum, new_path) return left or right
# @param root, a tree node # @param sum, an integer # @return a list of lists of integers defpathSum(self, root, sum): # The same Solution object may be called more than once. self.paths = [ ] ifNone == root: return [ ] ### result = self.doPathSum(root, 0, sum, [ ]) returnself.paths