Given a binary tree, compute the sum of all the branches in the tree. 1 branch is the path from the root to a leaf.
Consider the binary tree
[1]
/ \
[2] [3]
Output: [3, 4]
[1]-[2]
= 3
[1]-[3]
= 4
[3, 4]
The number of nodes in the tree is in the range [0, 5000].
-1000 <= BinaryTree.value <= 1000
Click to reveal
Try creating a helper function that takes into account a Global Sums
array and a Running Sum
variable to keep into account the summations of values
Click to reveal
Check if the node you're currently at is a leaf node or node. Can it help you reaching the base case?