747. 至少是其他数字两倍的最大数/C++

int dominantIndex(vector<int>& nums) {
    if(nums.size()==1)
        return 0;
    
    int max=-1,max2=-1;
    int maxIndex=-1;
    for(int i=0;i<nums.size();++i){
        if(nums[i]>=max){
            max2=max;
            max=nums[i];
            maxIndex=i;
        }
        else if(nums[i]>max2)
            max2=nums[i];
    }
	return max>=2*max2?maxIndex:-1;
}

相关文章:

  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2021-12-01
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2021-05-26
  • 2021-11-20
  • 2021-08-30
  • 2021-11-10
  • 2021-07-09
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案