C++ super easy 6-line solution


  • 0
    M
        int dominantIndex(vector<int>& nums) {
            int m=0, pos=0;
            for(int i=0;i<nums.size();i++) {
                if(nums[i]>m) m=nums[i], pos=i;
            }
            for(int i=0;i<nums.size();i++) {
                if(nums[i]*2>m&&i!=pos) return -1;
            }
            return pos;
        }

Log in to reply
 

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