Simple Java Solution beats 89.97%


  • 0
    K

    '''
    String[] list = new String[nums.length];
    HashMap<Integer,Integer> map = new HashMap<>();
    for(int i = 0; i < nums.length;i++)
    map.put(nums[i],i);
    Arrays.sort(nums);
    int size = nums.length;
    for(int i = 0;i < nums.length; i ++){
    if(i == nums.length-1) list[map.get(nums[i])] = "Gold Medal";
    if(i == nums.length-2) list[map.get(nums[i])] = "Silver Medal";
    if(i == nums.length-3) list[map.get(nums[i])] = "Bronze Medal";
    if(i < nums.length-3) list[map.get(nums[i])] = String.valueOf(size);
    size--;
    }
    return list;
    '''
    Using Hashmap to locate the position of arrays.


Log in to reply
 

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