747. Largest Number At Least Twice of Others

class Solution {
    public int dominantIndex(int[] nums) {
        
        int max = 0 ;
        
        for(int i = 0 ; i < nums.length; i++){
            
            if(nums[i] > nums[max]) max = i;
            
        }
        
        for(int j = 0; j < nums.length; j++){
            
            if(nums[max] < nums[j] * 2 && max != j) return -1;
            
        }
        
        return max;
        
    }
}

你可能感兴趣的:(Leetcode简单一刷)