@@ -0,0 +1,1805 @@
+import java.util.HashMap;%0A%0A// 454. 4Sum II%0A/**%0A * Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A%5Bi%5D + B%5Bj%5D + C%5Bk%5D + D%5Bl%5D is zero.%0A * %0A * To make problem a bit easier, all A, B, C, D have same length of N where 0 %3C= N %3C= 500. All integers are in the range of -2%5E28 to 2%5E28 - 1 %0A * and the result is guaranteed to be at most 2%5E31 - 1.%0A * %0A * Example:%0A * %0A * Input:%0A * A = %5B 1, 2%5D%0A * B = %5B-2,-1%5D%0A * C = %5B-1, 2%5D%0A * D = %5B 0, 2%5D%0A * %0A * Output:%0A * 2%0A * %0A * Explanation:%0A * The two tuples are:%0A * 1. (0, 0, 0, 1) -%3E A%5B0%5D + B%5B0%5D + C%5B0%5D + D%5B1%5D = 1 + (-2) + (-1) + 2 = 0%0A * 2. (1, 1, 0, 0) -%3E A%5B1%5D + B%5B1%5D + C%5B0%5D + D%5B0%5D = 2 + (-1) + (-1) + 0 = 0%0A * %0A * Tags: Binary Search, Hash Table%0A * %0A * Similar Problems: (M) 4Sum%0A * %0A * Author: Xinyue Zhang%0A */%0Apublic class Solution %7B%0A    public int fourSumCount(int%5B%5D A, int%5B%5D B, int%5B%5D C, int%5B%5D D) %7B%0A        int n = A.length, res = 0;%0A        HashMap%3CInteger, Integer%3E map = new HashMap%3CInteger, Integer%3E();%0A        //initiate hashmap%0A        for (int i = 0; i %3C n; i++) %7B%0A            for (int j = 0; j %3C n; j++) %7B%0A                int sum = -(A%5Bi%5D + B%5Bj%5D);%0A                map.put(sum, map.containsKey(sum) ? map.get(sum) + 1 : 1);%0A            %7D%0A        %7D%0A        %0A        for (int i = 0; i %3C n; i++) %7B%0A            for (int j = 0; j %3C n; j++) %7B%0A                int sum = C%5Bi%5D + D%5Bj%5D;%0A                if (map.containsKey(sum)) %0A                    res += map.get(sum);%0A            %7D%0A        %7D%0A        %0A        return res;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D A = %7B1, 2%7D;%0A        int%5B%5D B = %7B-2, -1%7D;%0A        int%5B%5D C = %7B-1, 2%7D;%0A        int%5B%5D D = %7B0, 2%7D;%0A        Solution sol = new Solution();%0A        int res = sol.fourSumCount(A, B, C, D);%0A        System.out.println(res);%0A    %7D%0A    %0A%7D%0A

Create 454_4Sum_II.java