3ms c++


  • 0
    X
    class Solution {
    public:
        int dominantIndex(vector<int>& nums) {
            int ind[100];
            memset(ind, 0, sizeof(int) * 100);
            for(int i = 0; i < nums.size(); i++)
                ind[nums[i]] = i + 1;
            int c = 99;
            while(ind[c--] == 0);
            int max = c + 1;
            while(c >= 0 && ind[c] == 0)
                c--;
            return max - 2 * c >= 0 ? ind[max] - 1: -1;
        }
    };
    

Log in to reply
 

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