class Solution {
public:
int moreThanHalfNum_Solution(vector<int>& nums) {
int val = nums[0], count = 1;
for(int i = 1; i < nums.size(); i ++)
{
if(nums[i] == val)
{
count ++;
}
else
{
count --;
}
if(count == 0)
{
count = 1;
val = nums[i];
}
}
return val;
}
};