Skip to content

Commit 8b1a51f

Browse files
committed
Contains Duplicate II
1 parent 68cfe84 commit 8b1a51f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package leetcode2018;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class ContainsDuplicateII {
7+
public boolean containsNearbyDuplicate(int[] nums, int k) {
8+
Map<Integer,Integer> map = new HashMap<>();
9+
for(int i =0; i < nums.length; i++){
10+
if(map.containsKey(nums[i])){
11+
if((i-map.get(nums[i])) <= k) return true;
12+
13+
}
14+
map.put(nums[i], i);
15+
}
16+
return false;
17+
}
18+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy