Question: The code below is supposed to calculate and then return a list of all branch sums. so for example a tree thats root is 10
The code below is supposed to calculate and then return a list of all branch sums.
so for example a tree thats root is 10 and the left of the root is 5 and the right of the root is 14, the program should return [15, 24] However it doesnt and I want to know why. I feel like its because of me creating the sums() method and giving it a list return type. Therefore, because of the recursive call, it isnt returning the list like how I expected to, maybe? Please, can someone help explain why? Only method I wrote was sums(). The others are given.
class Program { // This is the class of the input root. Do not edit it. public static class BinaryTree { int value; BinaryTree left; BinaryTree right;
BinaryTree(int value) { this.value = value; this.left = null; this.right = null; } }
public static List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
