题目

[LeetCode]至少是其他数字两倍的最大数 

 

代码

class Solution {
public:
    int dominantIndex(vector<int>& nums) {
        vector<int> sortedNums=nums;
        std::sort(sortedNums.begin(),sortedNums.end());
        
        int last=sortedNums[nums.size()-1];
        int pre=sortedNums[nums.size()-2];
        int index=0;
        
        for(index=0;index<nums.size();index++)
        {
            if(last==nums[index])
                break;
        }
        
        if(last!=0&&pre==0)
            return index;
        if(last/pre>2||(last/pre==2&&last%pre>=0))
            return index;
        return -1;
    }
};

 

相关文章:

  • 2022-02-22
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2021-09-15
猜你喜欢
  • 2021-05-26
  • 2021-11-20
  • 2021-08-30
  • 2021-04-28
  • 2021-07-09
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案