@@ -0,0 +1,898 @@
+package leetcode;%0A%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0A/**%0A * https://leetcode.com/problems/contains-duplicate-ii/%0A */%0Apublic class Problem219 %7B%0A    public boolean containsNearbyDuplicate(int%5B%5D nums, int k) %7B%0A        // the key is the num value, the value is the index%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            int num = nums%5Bi%5D;%0A            if (map.containsKey(num)) %7B%0A                int idx = map.get(num);%0A                if (Math.abs(i - idx) %3C= k) %7B%0A                    return true;%0A                %7D%0A            %7D%0A            map.put(num, i);%0A        %7D%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem219 prob = new Problem219();%0A        System.out.println(prob.containsNearbyDuplicate(new int%5B%5D%7B99, 99%7D, 2));%0A    %7D%0A%7D%0A

Solve problem 219