class Solution {
public:
int majorityElement(vector<int>& nums) {
int n=nums.size();
int t=-1;
int cnt=0;
for(int i=0;i<n;i++){
if(cnt==0)t=nums[i];
if(nums[i]==t)cnt++;
else --cnt;
}
return t;
}
};