Skip to content

Commit ad8ef76

Browse files
committed
add 1261
1 parent fcbcd76 commit ad8ef76

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//coding:utf-8
2+
/***********************************************************
3+
Program: 1261
4+
Description: I think this one should be categorized as `easy`.
5+
Shanbo Cheng: [email protected]
6+
Date: 2020-01-09 21:31:49
7+
Last modified: 2020-01-09 21:32:26
8+
GCC version: 4.9.3
9+
***********************************************************/
10+
11+
class FindElements {
12+
unordered_set<int> vals;
13+
public:
14+
void helper(TreeNode* root, int val) {
15+
if(!root)
16+
return;
17+
root->val = val;
18+
vals.insert(val);
19+
if(root->left)
20+
helper(root->left, 2 * root->val + 1);
21+
if(root->right)
22+
helper(root->right, 2 * root->val + 2);
23+
}
24+
FindElements(TreeNode* root) {
25+
helper(root, root->val + 1);
26+
}
27+
28+
bool find(int target) {
29+
return vals.find(target) != vals.end();
30+
}
31+
};

0 commit comments

Comments
 (0)