class Solution {
public:
int majorityElement(vector<int>& nums) {
int cnt=1;
int res=nums[0];
for(int i=1;i<nums.size();i++)
{
if(nums[i]==res) cnt++;
else cnt--;
if(!cnt)
{
res=nums[i];
cnt=1;
}
}
return res;
}
};
标签:cnt,nums,int,元素,169,LeetCode
From: https://www.cnblogs.com/tangxibomb/p/17534591.html