3-liner C++


  • 0
    class Solution {
    public:
        int dominantIndex(vector<int>& nums) {
            int maxi=(int)distance(nums.begin(),max_element(nums.begin(),nums.end()));
            for (int i=0; i<nums.size(); ++i) if (i!=maxi && 2*nums[i]>nums[maxi]) return -1;
            return maxi;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.