标签:
int findMajority(const std::vector<int> &array)
{
assert(!array.empty ());
int majority = 0;
size_t counter = 0;
std::for_each(array.cbegin (), array.cend (), [&](int i)
{
if (counter == 0){
majority = i;
}else{
if (majority == i){
++counter;
}else{
--counter;
}
}
});
return majority;
}
标签:
原文地址:http://www.cnblogs.com/wuOverflow/p/5252121.html