forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1261.js
More file actions
30 lines (28 loc) · 638 Bytes
/
Copy path1261.js
File metadata and controls
30 lines (28 loc) · 638 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @param {TreeNode} root
*/
var FindElements = function(root) {
this.data = new Set();
root.val = 0;
this.data.add(0);
let dfs = node => {
if (node.left) {
node.left.val = node.val * 2 + 1;
this.data.add(node.left.val);
dfs(node.left);
}
if (node.right) {
node.right.val = node.val * 2 + 2;
this.data.add(node.right.val);
dfs(node.right);
}
}
dfs(root);
};
/**
* @param {number} target
* @return {boolean}
*/
FindElements.prototype.find = function(target) {
return this.data.has(target);
};