int NumberAppearMoreThanOneHalf(vactor numbers)
{
if (numbers.empty==0)
{
return 0;
}
map<int, int> m;
for(int i=0; i<numbers.size(); ++i)
{
++m[numbers[i]];
}
for(auto member:m)
{
int size = numbers.size();
if(member.second > size/2)
{
return member.first;
}
}
return 0;
}
原文地址:https://www.cnblogs.com/xjyxp/p/11451741.html
时间: 2024-10-19 20:24:31