@@ -0,0 +1,720 @@
+package buildingblock.hashing.lc219_containsduplicate2;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array%0A * such that nums%5Bi%5D = nums%5Bj%5D and the difference between i and j is at most k.%0A */%0Apublic class Solution %7B%0A%0A    public boolean containsNearbyDuplicate(int%5B%5D nums, int k) %7B%0A        Map%3CInteger,Integer%3E exist = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (exist.containsKey(nums%5Bi%5D)%0A                    && (i - exist.get(nums%5Bi%5D) %3C= k)) %7B%0A                return true;%0A            %7D%0A            exist.put(nums%5Bi%5D, i);%0A        %7D%0A        return false;%0A    %7D%0A%0A%7D%0A

leetcode-219 contains duplicate 2