//LeetCode169. 多数元素
class Solution {
public:
int majorityElement(vector<int>& s) {
int count = 0;
int temp = 0;
for (int i = 0; i < s.size(); i++) {
if (count == 0) {
temp = s[i];
count++;
}
else {
if (s[i] == temp) count++;
else count--;
}
}
return temp;
}
};
LeetCode169. 多数元素
最新推荐文章于 2024-08-20 10:34:34 发布