Hello.
While I understand and like the solution for this question, I was wondering what went wrong with my approach which follows the solution from the previous problem - All Paths for a Sum.
def find_sum_of_path_numbers(root):
total = 0
find_path_recursive(root,[],total)
return total
def find_path_recursive(node,cur_path,total):
if node is None:
return
cur_path.append(str(node.val))
if node.left is None and node.right is None:
total += int(ββ.join(list(cur_path)))
else:
find_path_recursive(node.left,cur_path,total)
find_path_recursive(node.right,cur_path,total)
del cur_path[-1]
The result returned 0 for the above code.
Thank you so much for explaining in advance. Much appreciated.
Type your question above this line.
Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/5675214360805376