Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

506. Relative Ranks #176

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

public class Solution { public String[] findRelativeRanks(int[] nums) { Integer[] index = new Integer[nums.length]; for(int i = 0; i < nums.length; i++) { index[i] = i; } Arrays.sort(index, (a, b) -> (nums[b] - nums[a])); String[] res = new String[nums.length]; for(int i = 0; i < nums.length; i++) { if(i == 0) { res[index[i]] = "Gold Medal"; } else if(i == 1) { res[index[i]] = "Silver Medal"; } else if(i == 2) { res[index[i]] = "Bronze Medal"; } else { res[index[i]] = Integer.toString(i + 1); } } return res; } }