Skip to content

Commit cb0c01b

Browse files
grc-cohort-22#9 finished
1 parent 8f021f9 commit cb0c01b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/Practice.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,17 @@ private static int sumTree(BinaryTreeNode<Integer> root) {
242242
* @return the sum of all the tree's values
243243
*/
244244
public static int nbSum(TreeNode<Integer> root) {
245-
return 0;
245+
if (root == null) {
246+
return 0;
247+
}
248+
249+
int sum = root.data;
250+
251+
for (TreeNode<Integer> child : root.children) {
252+
sum += nbSum(child);
253+
}
254+
255+
return sum;
246256
}
247257

248258
/**

0 commit comments

Comments
 (0)