Skip to content

Commit 9cdb8bd

Browse files
authored
Create 653. Two Sum IV - Input is a BST
1 parent f875853 commit 9cdb8bd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Tree/653. Two Sum IV - Input is a BST

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
private :
3+
unordered_set<int> s ;
4+
5+
public:
6+
bool findTarget(TreeNode* root, int k) {
7+
8+
if(root == NULL)
9+
{
10+
return false ;
11+
}
12+
13+
if(s.count(k - root->val))
14+
{
15+
return true ;
16+
}
17+
s.insert(root->val);
18+
19+
return findTarget(root->left , k) || findTarget(root->right , k);
20+
}
21+
};

0 commit comments

Comments
 (0)