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 ...
随机推荐
- MonoBehaviour生命周期
MonoBehaviour生命周期 上图中重要的信息点很多,需要特别注意的是所有脚本的Awake方法都执行完才会执行Start,但是如果在Awake 中开启了一个协程这个协程中每一帧执行一些操作然后等 ...
- 【C#】枚举
枚举 public static class CommonEnums { public enum people { /// <summary> ///男人 /// </summary ...
- JS编写自己的富文本编辑器
富文本编辑器,网上有很多功能齐全种类丰富的如百度的Ueditor,简单适用型的如WangEditor等等.在经过一番挑选后,我发现都不适用现在的项目,然后决定自己造轮子玩玩.富文本编辑器中主要涉及到J ...
- coursera网站中的VTT字幕的使用
coursera网站中的VTT字幕的使用 1.https://www.coursera.org/learn/os-virtsecurity/lecture/xuWgP/1-3-cao-zuo-xi-t ...
- dzzoffice网盘应用有着最强大的团队、企业私有网盘功能,并且全开源无功能限制。
企业,团队多人使用dzzoffice的网盘应用,灵活并且功能强大. 支持个人网盘,机构部门,群组,并可根据使用情况开启关闭.例如可只开启群组功能. 可通过后缀,标签自定义类型进行快捷筛选 全面 ...
- Architecture:架构 元素与关系
http://www.iso-architecture.org/42010/cm/ Systems have architectures. In the Standard, the architect ...
- Ioc 之 Unity的依赖注入
Unity是微软官方提供的一个Ioc容器,用来实现依赖注入,减少代码之间的耦合程度.使用Unity实现Ioc方式有两种,一种是使用代码方式实现,一种是利用配置文件来实现. 我们先来看一下代码方式是如何 ...
- ubuntu卡机
卡机了用ctrl+alt+t打开终端然后top看后台程序 最后kill -9 + PID就能把最影响问题的程序杀掉 我之前就杀了一个占100%cpu的程序
- PRJ0003 : Error spawning 'midl.exe'
原因:出现该错误的是由于:C:\Program Files\Microsoft SDKs\Windows\v6.0A midl.exe 和midlc.exe缺失. 解决方法:从别人电脑上拷贝这个两个文 ...
- CPP-基础:快速排序
快速排序(Quicksort)是对冒泡排序的一种改进. 它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分 ...