Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public boolean containsNearbyDuplicate(int[] nums, int k) {
- Map<Integer,Integer> map = new HashMap<Integer,Integer>();
- for(int i=0;i<nums.length;i++)
- {
- if(map.containsKey(nums[i]))
- {
- int pre = map.get(nums[i]);
- if(i-pre<=k) return true;
- }
- map.put(nums[i],i);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement