1. 题目

2. 方法一
2.1. 代码
class Solution {
public:
bool findTarget(TreeNode* root, int k) {
stack<TreeNode*> tempstack;
tempstack.push(root);
set<int> valset;
while(!tempstack.empty()){
auto it=tempstack.top();
tempstack.pop();
if(it->left!=NULL) tempstack.push(it->left);
if(it->right!=NULL) tempstack.push(it->right);
if(valset.count(k-it->val))
return true;
valset.insert(it->val);
}
return false;
}
};
2.2. 结果

相关文章:
-
2022-12-23
-
2022-12-23
-
2021-05-11
-
2021-08-31
-
2022-12-23
-
2021-10-14
-
2021-10-06
-
2021-07-30