Advertisement
Kali_prasad

return element occured more than n/3 times

Mar 17th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.22 KB | None | 0 0
  1. int Solution::repeatedNumber(const vector<int> &A) {
  2.    
  3.     int n=A.size();
  4.     n/=3;
  5.     map<int,int> m;
  6.     for(auto x:A)
  7.     {
  8.         m[x]++;
  9.         if(m[x]>n)
  10.         return x;
  11.     }
  12.  
  13.     return -1;
  14.  
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement