All Paths for a Sum with return issues
问题 I have a question in finding the all paths for a sum. The question is: Given a binary tree and a number ‘S’, find all paths from root-to-leaf such that the sum of all the node values of each path equals ‘S’. My approach with recursion is: def all_sum_path(root, target): result = [] find_sum_path(root, target, result, []) return result def find_sum_path(root, target, result, new_path): if not root: return None new_path.append(root.value) diff = target - root.value if not root.left and not root