跳至主要內容

162. 寻找峰值

T4mako算法数组哈希表分治排序小于 1 分钟

162. 寻找峰值

简单

题目描述open in new window

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