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. 汇编笔记 CALL(1)

    assume cs:code code segment start: mov ax, ;将AX通用寄存器设0 call s inc ax s: pop ax ;将数据从桟中取出 code ends e ...

  2. iOS 使用宏定义函数和代码块

    iOS使用宏定义函数和代码块 今天在开发过程中碰到一个问题:就是父类中要向外发送通知,然后子类中或者其他类中来接收它.当然一般是把它写到类方法中去,但是有个问题,就是如果调用的类不是它的子类,就不能直 ...

  3. js的事件处理与闭包:

    var i = 0; for(i=0;i<5;i++){ (function(i){ setTimeout(function(){alert(i)},3000); })(i) } // 上面打印 ...

  4. ActiveMq 高级特性的使用

    消费者的 destination 可以使用 wildcards 生产者的 destination 可以使用 composite destinations VirtualTopic 真是一大利器,当初读 ...

  5. 微信支付:微信支付遇到的坑:jssdk,phpdemo,微信支付提示{"errMsg":"chooseWXPay:fail"}

    微信支付:微信支付遇到的坑:jssdk,phpdemo 使用微信支付,真是变态,如果不是微信用户多,我才不适配微信支付,我就在想:为什么没人用我支付宝的[点点虫]呢.一个小小的“/”的误差,都调不起微 ...

  6. 存储过程,游标,异常捕捉 try catch 实例代码

    1.存储过程代码.  (数据库是 AdventureWorks) 存储过程用来将错误信息插入到指定的表中. 在别的地方可以调用存储过程插入错误信息(下面部分代码 生成一个表,如果表已经存在就会插入错误 ...

  7. nodeJs爬虫小程序练习

    //爬虫小程序 var express = require('express'); //superagent是一个http的库,可以发起get和post请求 var superagent = requ ...

  8. mac系统卸载mono

    官方页面:http://www.mono-project.com/docs/about-mono/supported-platforms/osx/#uninstalling-mono-on-mac-o ...

  9. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  10. MySQL 分区知识点(二)

    前言: MySQL 5.1+ 版本就开始支持分区功能了. 分区本质上就是在物理文件层面划分了多个物理子表来支撑,或者说是一组底层表的句柄对象的封装. 对于分区表的请求,都是通过句柄对象转化成对存储引擎 ...