MCPcopy Create free account
hub / github.com/apna-college/Alpha / convertToSumTree

Method convertToSumTree

16_BinaryTrees/SumTree.java:13–26  ·  view source on GitHub ↗
(Node root)

Source from the content-addressed store, hash-verified

11 }
12
13 public static int convertToSumTree(Node root) {
14 if(root == null) {
15 return 0;
16 }
17
18 int leftVal = convertToSumTree(root.left);
19 int rightVal = convertToSumTree(root.right);
20 int leftSubtree = root.left == null ? 0 : root.left.data;
21 int rightSubtree = root.right == null ? 0 : root.right.data;
22
23 int myData = root.data;
24 root.data = leftSubtree + leftVal + rightSubtree + rightVal;
25 return myData;
26 }
27
28 public static void preorder(Node root) {
29 if(root == null) {

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected