Clean C++ solution


  • 0
    T
    int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
     unordered_map<int,int> AB,CD;
     int res = 0;
     for(a : A)
         for(b : B)
             AB[a+b]++;
     for(c : C)
         for(d : D)
             CD[-1 * (c+d)]++;
     for(auto it = AB.begin(); it != AB.end() ; ++it)
         if(CD.find(it->first) != CD.end())
             res += it->second * CD[it->first];
     return res;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.