@@ -0,0 +1,956 @@
+/**%0A *%09Given an array of integers and an integer k, %0A *%09find out whether there there are two distinct indices i and j in the array %0A *%09such that nums%5Bi%5D = nums%5Bj%5D and the difference between i and j is at most k.%0A *%0A *%09Author: matao%0A *%0A */%0A%0Aimport java.util.HashMap;%0A%0Apublic class ContainsDuplicateII %7B%0A    public static boolean containsNearbyDuplicate(int%5B%5D nums, int k) %7B%0A        if(nums == null %7C%7C nums.length == 0) %7B%0A        %09return false;%0A        %7D%0A        HashMap%3CInteger, Integer%3E map = new HashMap%3CInteger, Integer%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A        %09if(map.containsKey(nums%5Bi%5D) && (i - map.get(nums%5Bi%5D)) %3C= k) %7B%0A        %09%09return true;%0A        %09%7D%0A        %09map.put(nums%5Bi%5D, i);%0A        %7D%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09int%5B%5D nums1 = %7B1, 2, 3, 4, 3%7D;%0A    %09System.out.println(containsNearbyDuplicate(nums1, 2));%0A    %09System.out.println(containsNearbyDuplicate(nums1, 1));%0A    %7D%0A%7D

add Contains DuplicateII solution