package leetcode;

/**
 * https://leetcode.com/problems/4sum-ii/
 */
public class Problem454 {
    public int fourSumCount(int[] A, int[] B, int[] C, int[] D) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem454 prob = new Problem454();
        System.out.println(prob.fourSumCount(
            new int[]{1, 2}, new int[]{-2, -1}, new int[]{-1, 2}, new int[]{0, 2}
        )); // 2
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -215,274 +215,697 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem454 prob = new Problem454();%0A        System.out.println(prob.fourSumCount(%0A            new int%5B%5D%7B1, 2%7D, new int%5B%5D%7B-2, -1%7D, new int%5B%5D%7B-1, 2%7D, new int%5B%5D%7B0, 2%7D%0A        )); // 2
+Map%3CLong, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C A.length; i++) %7B%0A            for (int j = 0; j %3C B.length; j++) %7B%0A                long sum = A%5Bi%5D + B%5Bj%5D;%0A                if (!map.containsKey(sum)) %7B%0A                    map.put(sum, 1);%0A                %7D else %7B%0A                    map.put(sum, map.get(sum) + 1);%0A                %7D%0A            %7D%0A        %7D%0A        int result = 0;%0A        for (int i = 0; i %3C C.length; i++) %7B%0A            for (int j = 0; j %3C D.length; j++) %7B%0A                long sum = C%5Bi%5D + D%5Bj%5D;%0A                if (map.containsKey(-sum)) %7B%0A                    result += map.get(-sum);%0A                %7D%0A            %7D%0A        %7D%0A        return result;
 %0A   

Solve problem 454