package leetcode;

/**
 * https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k/
 */
public class Problem2006 {
    public int countKDifference(int[] nums, int k) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem2006 prob = new Problem2006();
        System.out.println(prob.countKDifference(new int[]{1,2,2,1}, 1)); // 4
        System.out.println(prob.countKDifference(new int[]{1,3}, 3)); // 0
        System.out.println(prob.countKDifference(new int[]{3,2,1,5,4}, 2)); // 3
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -244,366 +244,401 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem2006 prob = new Problem2006();%0A        System.out.println(prob.countKDifference(new int%5B%5D%7B1,2,2,1%7D, 1)); // 4%0A        System.out.println(prob
+Map%3C/* num */ Integer, /* count */ Integer%3E map = new HashMap%3C%3E();%0A        for (int num : nums) %7B%0A            map.put(num, map.getOrDefault(num, 0) + 1);%0A        %7D%0A        int answer = 0;%0A        for (int num : map.keySet()) %7B%0A            int a = num - k;%0A            if (map
 .co
-u
 nt
-KDifference(new int%5B%5D%7B1,3%7D, 3)); // 0%0A        System.out.println(prob.countKDifference(new int%5B%5D%7B3,2,1,5,4%7D, 2)); // 3
+ainsKey(a)) %7B%0A                answer += map.get(num) * map.get(a);%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 2006