LeetCode-Solutions-in-Cpp17

Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.


Project maintained by downdemo Hosted on GitHub Pages — Theme by mattgraham
class Solution {
 public:
  int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C,
                   vector<int>& D) {
    unordered_map<int, int> m;
    int sz = size(A);
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        ++m[A[i] + B[j]];
      }
    }
    int res = 0;
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        if (m.count(-C[i] - D[j])) {
          res += m[-C[i] - D[j]];
        }
      }
    }
    return res;
  }
};