力扣第169题 多数元素
class Solution {
public:
int majorityElement(vector<int>& nums) {
int res = 0, value = 0, len = nums.size();
for (int i = 0; i < len; i++)
{
if (value == 0)
{
res = nums[i];
}
value += (res == nums[i]) ? 1 : -1;
}
return res;
}
};