Skip to content

Commit 56b3ccb

Browse files
committed
Runtime: 88 ms (Top 52.38%) | Memory: 42.9 MB (Top 9.52%)
1 parent 2152c42 commit 56b3ccb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

scripts/algorithms/B/Binary Tree Pruning/Binary Tree Pruning.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// Runtime: 88 ms (Top 52.38%) | Memory: 42.9 MB (Top 9.52%)
2+
13
/**
24
* Definition for a binary tree node.
35
* function TreeNode(val, left, right) {
4-
* this.val = (val===undefined ? 0 : val)
5-
* this.left = (left===undefined ? null : left)
6-
* this.right = (right===undefined ? null : right)
6+
* this.val = (val===undefined ? 0 : val)
7+
* this.left = (left===undefined ? null : left)
8+
* this.right = (right===undefined ? null : right)
79
* }
810
*/
911
/**
@@ -18,14 +20,14 @@ var pruneTree = function(root) {
1820
}
1921
node.left = rec(node.left);
2022
node.right = rec(node.right);
21-
// For updated tree structure if threre are leaf nodes with zero value present, if yes then return null otherewise return node itself.
23+
// For updated tree structure if threre are leaf nodes with zero value present, if yes then return null otherewise return node itself.
2224
if(node.val===0 && node.left == null && node.right == null){
2325
return null
2426
}
2527
return node;
2628
}
2729
rec (root);
2830
if(root.val == 0 && root.left == null && root.right == null) return null
29-
31+
3032
return root;
31-
};
33+
};

0 commit comments

Comments
 (0)