public:
int majorityElement(vector
map
for (int ii = 0; ii < num.size(); ++ii) {
int count = m[num[ii]];
m[num[ii]] = ++count;
}
int maxEle = 0;
int maxCount = 0;
for(auto it = m.begin(); it != m.end(); ++it) {
if (it->second > maxCount) {
maxEle = it->first;
maxCount = it->second;
}
}
return maxEle;
}
};
No comments:
Post a Comment