标签:
看了一天电影果然弱智啊
这么简单的题目居然bug
public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { if(nums==null||nums.length<2) return false; HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>(); for(int i=0;i<nums.length;i++){ if(!hm.containsKey(nums[i])){ hm.put(nums[i],i); }else{ if(i-hm.get(nums[i])<=k){ return true; } } } return false; } }
标签:
原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4539759.html