leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0454.cpp (607B)


      1 class Solution {
      2   public:
      3     int fourSumCount(const vector<int> &nums1, const vector<int> &nums2, const vector<int> &nums3,
      4                      const vector<int> &nums4) const {
      5         const int n = size(nums1);
      6         unordered_map<int, int> um;
      7         int res = 0;
      8 
      9         for (int i = 0; i < n; i++) {
     10             for (int j = 0; j < n; j++) {
     11                 um[nums1[i] + nums2[j]]++;
     12             }
     13         }
     14 
     15         for (int i = 0; i < n; i++) {
     16             for (int j = 0; j < n; j++) {
     17                 res += um[-(nums3[i] + nums4[j])];
     18             }
     19         }
     20 
     21         return res;
     22     }
     23 };