simple solution


  • 0
    Z
    class Solution {
        public String[] findRelativeRanks(int[] nums) {
            
            int[] rank = new int[nums.length];
            rank = nums.clone();
            String[] output = new String[nums.length];
            Map<Integer,Integer> map = new HashMap<Integer,Integer>();
            Arrays.sort(rank);
            for(int i=nums.length-1;i>=0;i--){
                map.put(rank[i],nums.length-i); 
            }
            for(int i=0;i<nums.length;i++){
                if(map.get(nums[i])==1)      output[i]="Gold Medal";
                else if(map.get(nums[i])==2) output[i]="Silver Medal";
                else if(map.get(nums[i])==3) output[i]="Bronze Medal";
                else output[i]=map.get(nums[i])+"";
            }
            return output;
        }
    }
    

Log in to reply
 

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