class Solution { public: int MoreThanHalfNum_Solution(vector<int>& numbers) { int cur = 0, count = 0; for(int i = 0; i < numbers.size(); i++) { if(count == 0) { cur = numbers[i];//更新当前众数 count++; } else { if(cur == numbers[i]) { count++; } else { count--;//可能把众数也减掉了,但众数始终至少会多出一个 } } } if(count > 0) return cur; return 0; } };