219. Contains Duplicate II
2016-02-25 23:58
525 查看
public class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
Map<Integer,Integer>map=new HashMap<>();
for(int i=0;i<nums.length;i++){
if(!map.containsKey(nums[i])){
map.put(nums[i],i);
}
else{
int d=0;
d=i-map.get(nums[i]);
if(d<k+1)return true;
else map.put(nums[i],i);
}
}
return false;
}
}
public boolean containsNearbyDuplicate(int[] nums, int k) {
Map<Integer,Integer>map=new HashMap<>();
for(int i=0;i<nums.length;i++){
if(!map.containsKey(nums[i])){
map.put(nums[i],i);
}
else{
int d=0;
d=i-map.get(nums[i]);
if(d<k+1)return true;
else map.put(nums[i],i);
}
}
return false;
}
}
相关文章推荐
- UVA 442(p141)----Matrix Chain Multiplication
- UVA 253(p97)----Cube painting
- 研究一下TForm.WMPaint过程(也得研究WM_ERASEBKGND)——TForm虽然继承自TWinControl,但是自行模仿了TCustomControl的全部行为,一共三种自绘的覆盖方法,比TCustomControl还多一种
- TPanel的默认颜色存储在dfm中,读取后在Paint函数中设置刷子的颜色,然后填充整个背景
- LightOJ 1236 Pairs Forming LCM(唯一分解定理)
- IielgnairTs'lacsaP.119
- poll_wait阻塞/唤醒
- elgnairTs'lacsaP.118
- HA(高可用)集群之AIS(corosync),高可用httpd+NFS
- TWinControl.DefaultHandler里的CallWindowProc(FDefWndProc)还挺有深意的,TButton对WM_PAINT消息的处理就是靠它来处理的(以前不明白为什么总是要调用inherited,其实就是没有明白TWinControl.DefaultHandler的真正用处,而且还很有用)
- Rails铁轨(栈)
- hdu 1789 Doing Homework Again!
- MessagingTimeout: Timed out waiting for a reply to message ID
- main()函数
- Failed to download samples index, please check your connection and try again 解决
- how to tell if a library contain debug symbols or not
- Ubuntu下安装ideaIU14并添加桌面快捷方式
- type_traits之has_* 系列
- 安装cuda时 提示toolkit installation failed using unsupported compiler解决方法
- “Unable to open log device '/dev/log/main': No such file or directory”