Posted on

Description

Submission

class Solution {
public:
    int dominantIndex(vector<int>& nums) {
        auto it = max_element(nums.begin(), nums.end());

        for(auto x: nums) {
            if(x == *it) continue;
            if(*it < 2 * x) return -1;
        }
        
        return it - nums.begin();
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *