Given scores of N athletes, find their relative ranks andthe people withthe top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal"and"Bronze Medal".
Input: [5, 4, 3, 2, 1] Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"] Explanation: The firstthree athletes got the top three highest scores, so they got "Gold Medal", "Silver Medal"and"Bronze Medal". For the left two athletes, you just need to output their relative ranks according to their scores.
public String[] findRelativeRanks(int[] nums) { String[] s =new String[nums.length]; int max =0; for(int i : nums){ if(i> max){ max= i; } } int[] index =newint[max+1]; for(int i =0 ;i< nums.length ;i++){ index[nums[i]] =i+1; //在这里加一是因为如果不加一那么第一个索引的数组之在index里面会是0,不好区分。 }