class Solution {

public:

int majorityElement(vector<int>& nums) {

int n = nums.size();

int lastOne = nums[0];

int cnt = 1;

for(int i = 1;i<n;++i)

{

```
if(nums[i]!=lastOne)
--cnt;
else
++cnt;
if(cnt == 0)
{
lastOne = nums[i];
++cnt;
}
}
return lastOne;
}
```

};