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. thinkphp中如何使用phpspreadsheet插件

    thinkphp中如何使用phpspreadsheet插件 一.总结 一句话总结:多百度,百度什么都有 1.thinkphp中用composer安装的插件的命名空间是什么? use PhpOffice ...

  2. QT5 QtreeWidget 实现点击item事件以及右键菜单删除item 和 重命名item

    1.new 一个QTreeWidget 对象,并设置头标签,和根节点(个人程序需要) QTreeWidget* treeWidget = ui.treeWidget;//我已经在ui设计师中拖了一个Q ...

  3. Asp.net 使用 Jsonp

    简介 由于JavaScript的安全机制,ajax不支持跨域调用.所以出现了jsonp. 实现 服务器 public string Jsonp(string name) { string result ...

  4. LeetCode OJ:Binary Tree Level Order Traversal II(二叉树的层序遍历)

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  5. 面试题13:在O(1)时间删除链表结点

    题目:给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点. 链表结点与函数的定义如下: struct ListNode { int val; ListNode* next; }; ...

  6. 手动安装mysql-5.0.45.tar.gz

    Linux下编译安装 安装环境:VMware9(桥接模式) + Linux bogon 2.6.32-642.3.1.el6.x86_64(查看linux版本信息:uname -a) 先给出MySQL ...

  7. MKMapView缩放显示全部annotation(转)

    原文  http://blog.csdn.net/favormm/article/details/8028026#define MINIMUM_ZOOM_ARC 0.014 //approximate ...

  8. 【集成学习】sklearn中xgboot模块中fit函数参数详解(fit model for train data)

    参数解释,后续补上. # -*- coding: utf-8 -*- """ ############################################## ...

  9. vector的内存分配机制分析

    该程序初步演示了我对vector在分配内存的时候的理解.可能有误差,随着理解的改变,改代码可以被修改. /* 功能说明: vector的内存分配机制分析. 代码说明: vector所管理的内存地址是连 ...

  10. (C#)Windows Shell 外壳编程系列3 - 上下文菜单(iContextMenu)(一)右键菜单

    (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳编程系列2 - 解释,从“桌面”开始展开 这里解释上一节中获取名称的方法 GetD ...