[C++] STL makes good

  • 0
    class FourSum {
        int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
            unordered_map<int, int> ab, cd;
            for (int i : A) for (int j : B) ab[i+j]++;
            for (int i : C) for (int j : D) cd[i+j]++;
            int res = 0;
            for (auto i : ab)
                res += i.second * cd[-i.first];
            return res;

Log in to reply

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