class Solution {
public:
int moreThanHalfNum_Solution(vector<int>& nums) {
//发现竟然也是计算机统考算法题
int cnt = 1,val = nums[0];
for(auto x:nums){
if(val == x) cnt++;
else cnt--;
if(cnt == 0){
val = x;
cnt = 1;
}
}
return val;
}
};