File tree 1 file changed +8
-6
lines changed
scripts/algorithms/B/Binary Tree Pruning
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 88 ms (Top 52.38%) | Memory: 42.9 MB (Top 9.52%)
2
+
1
3
/**
2
4
* Definition for a binary tree node.
3
5
* 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)
7
9
* }
8
10
*/
9
11
/**
@@ -18,14 +20,14 @@ var pruneTree = function(root) {
18
20
}
19
21
node . left = rec ( node . left ) ;
20
22
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.
22
24
if ( node . val === 0 && node . left == null && node . right == null ) {
23
25
return null
24
26
}
25
27
return node ;
26
28
}
27
29
rec ( root ) ;
28
30
if ( root . val == 0 && root . left == null && root . right == null ) return null
29
-
31
+
30
32
return root ;
31
- } ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments