class Solution {
public:
bool findTarget(TreeNode* root, int k) {
queue<TreeNode> Q;
vector<int> V;
if (root != NULL)
{
Q.push(*root);
while (!Q.empty())
{
TreeNode livenode = Q.front();
Q.pop();
V.push_back(livenode.val); if (livenode.left != NULL)
{
Q.push(*livenode.left);
}
if (livenode.right != NULL)
{
Q.push(*livenode.right);
}
} sort(V.begin(), V.end()); for (int i = ; i < V.size(); i++)
{
for (int j = ; j < V.size(); j++)
{
int x = V[i];
int y = V[j];
if (x + y < k)
{
continue;
}
if (x + y == k&&i != j)
{
return true;
}
if (x + y > k)
{
break;
}
}
}
}
return false;
}
};

leetcode653的更多相关文章

  1. [Swift]LeetCode653. 两数之和 IV - 输入 BST | Two Sum IV - Input is a BST

    Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...

  2. Leetcode653.Two Sum IV - Input is a BST两数之和4-输入BST

    给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. struct TreeNode { int val; struct TreeNode * ...

  3. LeetCode653. 两数之和 IV - 输入 BST

    题目 直接暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 bool findTarget(TreeNode* root, int k ...

  4. LeetCode 653. 两数之和 IV - 输入 BST(Two Sum IV - Input is a BST)

    653. 两数之和 IV - 输入 BST 653. Two Sum IV - Input is a BST 题目描述 给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定 ...

随机推荐

  1. tyvj 1402 乌龟棋 dp

    P1402 [NOIP2010]乌龟棋 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2010提高组复赛第二题 描述 小明过生日的时候,爸爸送给他一 ...

  2. 智课雅思词汇---二十一、名词性后缀acity是什么意思

    智课雅思词汇---二十一.名词性后缀acity是什么意思 一.总结 一句话总结:后缀:-acity [名词后缀] 构成抽象名词,表示性质.状态.情况.与形容词后缀-acious相对应 rapacity ...

  3. Linux 下安装 jdk-7u75-linux-x64.gz,jdk1.7.0_75,jdk1.7步骤:

    摘要:近来又用到了Linux系统,所以就又新装了一个虚拟机和CentOS 6.4来用,搞开发的程序猿们可能都知道,在现在的很多企业中,生产环境大多都是Linux服务器,并且用的比较多的大都是CentO ...

  4. hdu4451 Dressing(容斥原理)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  5. hihocoder 1049 后序遍历树

    #include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #inc ...

  6. poj2336

    题目大意:一个船要把n个车渡过河  船最多载m辆车  把车运过去需要t的时间 回来也要t的时间 给定n辆车依次到河边的时间 求最短运送时间  还有最短跑几趟 一维dp  可以直接d运送时间 dp[i] ...

  7. HDU - 1506 Largest Rectangle in a Histogram (单调栈/笛卡尔树)

    题意:求一个直方图中最大矩形的面积. 很经典的一道问题了吧,可以用单调栈分别求出每个柱子左右两边第一个比它低的柱子(也就相当于求出了和它相连的最后一个比它高的柱子),确定每个柱子的左右边界,每个柱子的 ...

  8. LeetCode Perfect Number

    原题链接在这里:https://leetcode.com/problems/perfect-number/#/description 题目: We define the Perfect Number ...

  9. deque容器

    一.deque容器基本概念 deque是“double-ended queue”的缩写,和vector一样,deque也支持随机存取.vector是单向开口的连续性空间,deque则是一种双向开口的连 ...

  10. QT 中“ std::cerr ”的使用方法【转载】

    std::cerr  标准错误输出流 std::cout 标准输出流 std::cerr 与 std::cout的最大不同是 cerr 是 不带输出缓冲 的,直接就可以输出到显示器上, 而 cout ...