class Solution {
public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
int res = 0;
Map<Integer,Integer> map = new HashMap<>();
for(int i = 0 ; i < nums1.length ; i++){
for(int j = 0 ;j < nums2.length ; j++){
int sum = nums1[i] + nums2[j];
map.put(sum,map.getOrDefault(sum,0)+1);
}
}
for(int i = 0 ; i < nums3.length ; i++){
for(int j = 0 ;j < nums4.length ; j++){
res += map.getOrDefault(0-nums3[i]-nums4[j],0);
}
}
return res;
}
}
代码随想录算法训练营第六天 第454题.四数相加II
于 2023-06-13 20:13:49 首次发布