Contains Duplicate II
2015-12-11 15:11
417 查看
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in
the array such that nums[i] = nums[j] and the difference between i and jis
at most k.
the array such that nums[i] = nums[j] and the difference between i and jis
at most k.
class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { map<int,int> temp; for(int i=0;i<nums.size();i++){ if(temp.find(nums[i]) == temp.end()){ temp[nums[i]] = i; }else if(i - temp[nums[i]]<=k){ return true; }else{ temp[nums[i]] = i; } } return false; } };
相关文章推荐
- aix 计算性内存和文件内存
- AIX 配置vncserver
- 2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/法)
- Contains Duplicate
- Condor error:Failed to execute condor_exec.exe
- Aix命令大全
- DB2 创建EXPLAIN表
- 大家好,我叫 maigeqqcom
- 1290 Counting Diff Pairs
- Mac 应用开发--Cocoa运用程序显示或隐藏MainNemu
- rails 4 里面 用 link_to 来生成 delete调用,
- StoryBoard页面跳转方式 Show,Show Detail,Present Modally,Present as Popover
- Naive Bayes Classification
- Daily Scrum – 12/10
- Spirng+In+Action(Craig Walls Ryan Breidenbach)
- 远东转载这说明一些有实力的话人工智能协会的思维和潜意识之间移动的一篇文章
- VMware: Taking Ownership of this Virtual Machine Failed
- 31 Which of the following is a benefit of ASM fast disk resync? A. Failed disks are taken offline im
- notify 和 notifyall 的区别,yield 和 wait,sleep的区别
- 使用行为树(Behavior Tree)实现游戏AI