https://leetcode-cn.com/problems/4sum-ii/
//两数之和的升级版
//两数之和是指定等于某个数,这里是指定等于0而已,换汤不换药
//可以将两个数看成一个数,然后当作两数之和来做
//即分组+哈希表的办法
//先用两层循环统计出前两个数的和的可能
//用<key, value> = <sum, count>即<前两数的和, 这个和出现的次数>
class Solution {
public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
Map<Integer, Integer> table1 = new HashMap<>();
int sum = 0;
int count = 0;
for(int i = 0; i < nums1.length; i++){
for(int j = 0; j < nums2.length; j++){
sum = nums1[i] + nums2[j];
if(table1.containsKey(sum)){
table1.replace(sum, table1.get(sum)+1);
}
else table1.put(sum, 1);
}
}
sum = 0;
for(int i = 0; i < nums3.length; i++){
for(int j = 0; j < nums4.length; j++){
sum = nums3[i] + nums4[j];
if(table1.containsKey(0 - sum))
count = count + table1.get(0 - sum);
}
}
return count;
}
}










