problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::two_sum_iv_input_is_a_bst::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool findTarget (TreeNode *root, int k)
 

详细描述

在文件 leetcode.h1875 行定义.

成员函数说明

◆ findTarget()

bool leetcode::two_sum_iv_input_is_a_bst::Solution::findTarget ( TreeNode root,
int  k 
)
static

在文件 leetcode.cpp4894 行定义.

4894 {
4895 set<int> s;
4896 unordered_map<int, int> count;
4897 queue<TreeNode *> que;
4898 que.push(root);
4899 while(!que.empty()) {
4900 const auto *node = que.front();
4901 que.pop();
4902 s.insert(node->val);
4903 count[node->val]++;
4904 if(node->left != nullptr) {
4905 que.push(node->left);
4906 }
4907 if(node->right != nullptr) {
4908 que.push(node->right);
4909 }
4910 }
4911 bool ans = false;
4912 for(auto it = s.begin(); it != s.end(); ++it) {
4913 int other = k - *it;
4914 if(other == *it) {
4915 if(count[other] > 1) {
4916 ans = true;
4917 break;
4918 }
4919 } else if(s.contains(other)) {
4920 ans = true;
4921 break;
4922 }
4923 }
4924 return ans;
4925 }
vector< int > root
Definition: acwing408.cpp:349

引用了 acwing::acwing836_408::root.


该类的文档由以下文件生成: