leetcode——219—— Contains Duplicate II
2016-03-28 18:24
477 查看
Given an array of integers and an integer k, find out whether there are two distinct indicesi and
j in the array such that nums[i] = nums[j] and the difference betweeni and
j is at most k.
j in the array such that nums[i] = nums[j] and the difference betweeni and
j is at most k.
class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { unordered_map<int,int> map; for (int i = 0; i < nums.size(); ++i) { if (map.find(nums[i]) != map.end() && i - map[nums[i]] <= k) return true; else map[nums[i]] = i; } return false; } };
相关文章推荐
- 2014山东省第五届ACM省赛 angry_birds_again_and_again
- AI初步学习笔记
- SSH连接时出现Host key verification failed的原因及解决方法
- Ansible9:条件语句
- Ansible7:Playbook常用模块
- idea14 Server is not connected. Deploy is not available.
- aidl学习笔记(一)
- 一个挺好用的任务提示小软件 Rainlendar2
- 浙江科技学院第十三届程序设计竞赛 1008 A Heavy Rainy Day 贪心
- 多线线程async与await关键字
- AIDL示例
- ORA-04063: view "DAILY.TMP_TBX_100_0_S4" 有错误
- 《科学》封面重磅论文:人工智能终于能像人类一样学习
- paint画笔style为Stroke时circle的半径分析
- 文本分类——NaiveBayes
- Win7 64位 VS2015及MinGW环境编译矢量库agg-2.5和cairo-1.14.6
- http://blog.csdn.net/sevenquan/article/details/50687077
- AfxGetMainWnd()函数用法
- http://blog.csdn.net/friendan/article/details/12226201
- 百度地图系列05——显示屏幕范围内的marker