Java


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

Log in to reply
 

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