leetcode之twosum
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int>result;
int i,j,k;
map<int,int>h;
for(i=;i<nums.size();i++) {
if(!h.count(nums[i]))
h[nums[i]]=i+;
k=h[target-nums[i]];
if(k>&&k!=i+) {
result.push_back(k-);
result.push_back(i);
break;
}
}
return result;
}
};
leetcode之twosum的更多相关文章
- LeetCode #1 TwoSum
Description Given an array of integers, return indices of the two numbers such that they add up to a ...
- Leetcode 1——twosum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- LeetCode 之 TwoSum
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- leetcode ----ARRAY TWOSUM
代码的(判断nums[i]或者是target-nums[i]都可以):
- [LeetCode_1] twoSum
LeetCode: 1. twoSum 题目描述 Given an array of integers, return indices of the two numbers such that the ...
- LeetCode 算法题解 js 版 (001 Two Sum)
LeetCode 算法题解 js 版 (001 Two Sum) 两数之和 https://leetcode.com/problems/two-sum/submissions/ https://lee ...
- ANDROID学习书单
Skip to content PersonalOpen sourceBusinessExplore Sign upSign in PricingBlogSupport This reposito ...
- Android技能树
第一部分:Android(安卓)Android基础知识Android内存泄漏总结Handler内存泄漏分析及解决Android性能优化ListView详解RecyclerView和ListView的异 ...
- LeetCode初体验—twoSum
今天注册了大名鼎鼎的LeetCode,做了一道最简单的算法题目: Given an array of integers, return indices of the two numbers such ...
随机推荐
- PHP实现XML传输
sendXML.php <!--发送XML的页面--> <?php $xml_data = '<xml>...</xml>';//发送的xml $url ...
- AJPFX关于JAVA多线程实现的三种方式
JAVA多线程实现方式主要有三种:继承Thread类.实现Runnable接口.使用ExecutorService.Callable.Future实现有返回结果的多线程.其中前两种方式线程执行完后都没 ...
- [BZOJ1040][ZJOI2008]骑士 基环树DP
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1040 题目给出了$n$个点和$n$条无向边,即一棵基环树或者基环树森林. 如果题目给的关系 ...
- P1967 货车运输 未完成
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- 边框圆角值的问题、white-space、word-wrap、margin对布局的影响
1.边框圆角(border-radius)值的问题 border-radius : 7px 7px 7px 0; 四个值的顺序是左上.右上.右下.左下 2.white-space 规定段落中的文本不换 ...
- Android Platform Version 和 API Level对照
Platform Version API Level VERSION_CODE Notes Android 5.1 22 LOLLIPOP_MR1 Platform Highlights Androi ...
- Qt和Cocoa混合编程
https://el-tramo.be/blog/mixing-cocoa-and-qt/
- 图解GitHub
转自:http://marklodato.github.io/visual-git-guide/index-zh-cn.html 个人觉得这一篇比一些入门教程更值得看,图解很详细到位,很容易理解其工作 ...
- [Java 8] (8) Lambda表达式对递归的优化(上) - 使用尾递归 .
递归优化 很多算法都依赖于递归,典型的比如分治法(Divide-and-Conquer).但是普通的递归算法在处理规模较大的问题时,常常会出现StackOverflowError.处理这个问题,我们可 ...
- systemtap执行过程中报probe timer.profile registration error
probe timer.profile registration error 今天在执行火焰图的过程中,代码报错,probe timer.profile registration error 经过查询 ...