Simple Java Solution


  • 0
    L

    class Solution {
    public String[] findRelativeRanks(int[] nums) {

        String [] result=new String[nums.length];
        int size=nums.length;
       
        int[] clone = nums.clone();
        Arrays.sort(clone);
        
        
        
        Map<Integer,Integer> ranks=new HashMap<Integer,Integer>();
        for(int i=0;i<size;i++)
            ranks.put(clone[i],size-i);
        
        for(int i=0;i<size;i++)
        {
            int r=ranks.get(nums[i]);
            
            if(r==1)
                result[i]="Gold Medal";
            else if(r==2)
                result[i]="Silver Medal";
            else if(r==3)
                result[i]="Bronze Medal";
            else
                result[i]=Integer.toString(r);
        }
    
        return result;
    }
    

    }


Log in to reply
 

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