Simple code c++ O(N ^ 2)


  • 0
    K
    class Solution {
    public:
    	int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
    		unordered_map<int, int>m;
    		int size = A.size();
    		int ret = 0;
    		for (int i = 0; i < size; i++)
    			for (int j = 0; j < size; j++)
    				m[A[i] + B[j]] += 1;
    		for (int k = 0; k < size; k++)
    			for (int l = 0; l < size; l++)
    				ret += m[-C[k] - D[l]];
    				
    		return ret;
    	}
    };
    

Log in to reply
 

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