knakul853

Untitled

Jun 15th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
  7.        
  8.         int n = (int)A.size();
  9.        
  10.         unordered_map<int,int>mp;
  11.         for( int i=0;i<n;i++ )
  12.         {
  13.             for(int j=0;j<n; j++ )
  14.             {
  15.                 mp[A[i] + B[j]]++;
  16.             }
  17.         }
  18.        
  19.         int ans = 0;
  20.        
  21.          for( int i=0;i<n;i++ )
  22.         {
  23.             for(int j=0;j<n; j++ )
  24.             {
  25.               if(mp.count(-C[i]-D[j]))ans+=mp[-C[i]-D[j]];
  26.             }
  27.         }
  28.         return ans;
  29.        
  30.        
  31.     }
  32. };
Add Comment
Please, Sign In to add comment