@@ -0,0 +1,906 @@
+package array;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * leetcode no.532%0A */%0A%0Apublic class KDiffPairsInAnArray %7B%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D nums = new int%5B%5D %7B1, 2, 3, 4, 5%7D;%0A        int k = 1;%0A        System.out.println(findPairs(nums, k));%0A    %7D%0A%0A    public static int findPairs(int%5B%5D nums, int k) %7B%0A        if (nums.length == 0 %7C%7C nums == null %7C%7C k %3C 0)%0A            return 0;%0A        int count = 0;%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int n : nums)%0A            map.put(n, map.getOrDefault(n, 0) + 1);%0A        for (Map.Entry%3CInteger, Integer%3E entry : map.entrySet()) %7B%0A            if (k == 0) %7B%0A                if (entry.getValue() %3E= 2)%0A                    count++;%0A            %7D else %7B%0A                if (map.containsKey(entry.getKey() + k))%0A                    count++;%0A            %7D%0A        %7D%0A        return count;%0A    %7D%0A%7D%0A

add leetcode no.532