Java Solution with collection Framework Accepted one


  • -1
    R

    public int dominantIndex(int[] nums) {
    List<Integer> num=new ArrayList<>();
    for(int a:nums) {
    num.add(a);
    }
    Integer max= Collections.max(num);
    int maxIndex=num.indexOf(max);
    num.remove(maxIndex);
    Integer secondmax=Collections.max(num);
    if(max>=2*secondmax) {
    return maxIndex;
    }
    return -1;
    }


Log in to reply
 

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