Map based solution, what is the time and space complexity and how to improve this?


#1

int Solution::majorityElement(const vector &A) {
int n=A.size();
map<int,int> m;
for(int i=0;i<A.size();i++){
m[A[i]]++;
}
for(auto it: m){
if(it.second>floor(n/2)){
return it.first;
}
}
}