class Solution { public: int MoreThanHalfNum_Solution(vector<int> numbers) { int len = numbers.size(); if(len==0) return 0; sort(numbers.begin(),numbers.end()); int mid = numbers[len/2]; int sum=0; for(int i=0;i<len;i++) { if(numbers[i]==mid) sum++; } if(sum > len/2) return mid; return 0; } };
原文:https://www.cnblogs.com/loyolh/p/12342996.html