leetcode653
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的更多相关文章
- [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 ...
- Leetcode653.Two Sum IV - Input is a BST两数之和4-输入BST
给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. struct TreeNode { int val; struct TreeNode * ...
- LeetCode653. 两数之和 IV - 输入 BST
题目 直接暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 bool findTarget(TreeNode* root, int k ...
- LeetCode 653. 两数之和 IV - 输入 BST(Two Sum IV - Input is a BST)
653. 两数之和 IV - 输入 BST 653. Two Sum IV - Input is a BST 题目描述 给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定 ...
随机推荐
- Windows 安装Mysql8.0 绿色包
〇.准备: MySQL8.0 Windows zip包下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip 环 ...
- hadoop-0.20.1+120 hive-0.3.99.1+0 试用hwi(hive web interface
摘自:http://www.chinacloud.cn/show.aspx?id=3274&cid=12 [日期:2010-07-04] 来源:淘宝数据平台团队 作者: [字体:大 中 小] ...
- IDEA配置JavaWeb项目Artifacts
- Maven下载 || 配置本地仓库 || IntelliJ IDEA配置Maven教程
本文章主要介绍1.Maven下载 2.配置本地仓库Repository 3.IDEA配置Maven 三点. 相关博客: Eclipse配置Maven https://www.cnblogs.c ...
- 02-THREE.JS 辅助线使用
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- 【Cordova】Cordova开发
引言 微软开启新战略--移动为先,云为先.作为开发者,首先感受到的变化就是VS2015预览版增加了对各种跨平台框架的支持,极大方便了我们的开发.其中号称原生性能的Xamarin要收费,挺贵的,一般人还 ...
- Tomcat_总结_01_tomcat环境搭建
一.准备条件 1.安装jdk 二.安装tomcat 1.下载tomcat 去官网下载 64-bit Windows zip 版本的tomcat,并解压 https://tomcat.apache. ...
- BlockingQueue实现阻塞队列
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public cl ...
- web端测试小知识
1.测试web端会看请求.数据.定位问题 在浏览器中按F12按钮,然后继续操作 一个操作有时请求很多个接口,点击“preview”,查看返回的数据 ========================== ...
- LeetCode 340. Longest Substring with At Most K Distinct Characters
原题链接在这里:https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/ 题目: Give ...