162. 寻找峰值
小于 1 分钟
162. 寻找峰值简单
class Solution {
public int majorityElement(int[] nums) {
int x = 0;int votes = 0;
for(int num : nums){
if(votes == 0){
x = num;
}
votes += num == x ? 1 : -1;
}
return x;
}
}
Powered by Waline v2.15.5