class Solution {
public:
int MoreThanHalfNum_Solution(vector<int> numbers) {
if(numbers.size()==0)
{
return 0;
}
int sizes=numbers.size();
sort(numbers.begin(),numbers.end());//讲数组进行递增排序
int i,count=0,middle=numbers[numbers.size()/2];//取排序后数组的中间元素
for(i=0;i<sizes;i++) //只有数组中存在符合题意得元素,那数组中间元素肯定是这个元素
{
if(numbers[i]==middle)
{
count++;
}
}
return (count>numbers.size()/2)? middle:0;
}
};</int>