share my O(n^2) C++ 800ms easy-understanding code


  • 1
    H

    '''
    class Solution {
    public:
    int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
    unordered_map<int, int> mp;
    int ans = 0;
    for (int a:A)
    for (int b:B)
    ++mp[a+b];
    for(int c:C)
    for(int d:D)
    ans+=mp[-(c+d)];
    return ans;
    }
    };

    '''

    • list item

Log in to reply
 

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