public class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
if (nums.length <= 1 || k < 1) return false;
HashMap
lookup = new HashMap();
for (int i = 0; i < nums.length; i++){
if (lookup.containsKey(nums[i])&&(i - lookup.get(nums[i]).intValue() <= k)){
return true;
}
lookup.put(nums[i], i);
}
return false;
}
}
No comments:
Post a Comment