package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/relative-ranks/
 */
public class Problem506 {
    public String[] findRelativeRanks(int[] nums) {
        // TODO
        return new String[0];
    }

    public static void main(String[] args) {
        Problem506 prob = new Problem506();
        System.out.println(Arrays.toString(prob.findRelativeRanks(new int[]{5, 4, 3, 2, 1}))); // ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]
    }
}

@@ -34,17 +34,146 @@
 il.Array
-s
+List;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/**%0A 
@@ -314,296 +314,919 @@
     
-// TODO%0A        return new String%5B0%5D;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem506 prob = new Problem506();%0A        System.out.println(Arrays.toString(prob.findRelativeRanks(new int%5B%5D%7B5, 4, 3, 2, 1%7D))); // %5B%22Gold Medal%22, %22Silver Medal%22, %22Bronze Medal%22, %224%22, %225%22%5D
+int%5B%5D copy = Arrays.copyOf(nums, nums.length);%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C copy.length; i++) %7B%0A            list.add(copy%5Bi%5D);%0A        %7D%0A        Collections.sort(list, (a, b) -%3E Integer.compare(b, a));%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C list.size(); i++) %7B%0A            map.put(list.get(i), i + 1);%0A        %7D%0A        String%5B%5D result = new String%5Bnums.length%5D;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            int position = map.get(nums%5Bi%5D);%0A            if (position == 1) %7B%0A                result%5Bi%5D = %22Gold Medal%22;%0A            %7D else if (position == 2) %7B%0A                result%5Bi%5D = %22Silver Medal%22;%0A            %7D else if (position == 3) %7B%0A                result%5Bi%5D = %22Bronze Medal%22;%0A            %7D else %7B%0A                result%5Bi%5D = Integer.toString(position);%0A            %7D%0A        %7D%0A        return result;
 %0A   

Solve problem 506