File tree 1 file changed +11
-10
lines changed
scripts/algorithms/F/Find Elements in a Contaminated Binary Tree
1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 166 ms (Top 48.15%) | Memory: 52.1 MB (Top 16.67%)
1
2
/**
2
3
* Definition for a binary tree node.
3
4
* 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)
5
+ * this.val = (val===undefined ? 0 : val)
6
+ * this.left = (left===undefined ? null : left)
7
+ * this.right = (right===undefined ? null : right)
7
8
* }
8
9
*/
9
10
/**
10
11
* @param {TreeNode } root
11
12
*/
12
13
var FindElements = function ( root ) {
13
14
this . st = new Set ( )
14
-
15
+
15
16
recover = ( root , val ) => {
16
17
this . st . add ( val ) ;
17
- if ( root . left != null ) recover ( root . left , val * 2 + 1 )
18
- if ( root . right != null ) recover ( root . right , val * 2 + 2 )
18
+ if ( root . left != null ) recover ( root . left , val * 2 + 1 )
19
+ if ( root . right != null ) recover ( root . right , val * 2 + 2 )
19
20
}
20
-
21
+
21
22
recover ( root , 0 )
22
23
} ;
23
24
24
- /**
25
+ /**
25
26
* @param {number } target
26
27
* @return {boolean }
27
28
*/
28
29
FindElements . prototype . find = function ( target ) {
29
30
return this . st . has ( target )
30
31
} ;
31
32
32
- /**
33
+ /**
33
34
* Your FindElements object will be instantiated and called as such:
34
35
* var obj = new FindElements(root)
35
36
* var param_1 = obj.find(target)
36
- */
37
+ */
You can’t perform that action at this time.
0 commit comments