国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

506. Relative Ranks (E)

2019-11-08 01:35:38
字體:
來源:轉載
供稿:網友

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".

Example 1:

Input: [5, 4, 3, 2, 1]Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]Explanation: The first three 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.

Note:

N is a positive integer and won't exceed 10,000.All the scores of athletes are guaranteed to be unique.

Subscribe to see which companies asked this question.

My Solution:

public class Solution {    public String[] findRelativeRanks(int[] nums) {        Map<Integer,Integer> map=new HashMap<Integer,Integer>();        for(int i=0;i<nums.length;++i){            map.put(nums[i],i);        }        Arrays.sort(nums);        String[] re=new String[nums.length];        int rank=nums.length;        for(int i=0;rank>0;rank--,i++){            switch(rank){                case 1:                    re[map.get(nums[i])]="Gold Medal";                    break;                case 2:                    re[map.get(nums[i])]="Silver Medal";                    break;                case 3:                    re[map.get(nums[i])]="Bronze Medal";                    break;                default:                    re[map.get(nums[i])]=Integer.toString(rank);                    break;            }          }        return re;    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三原县| 江口县| 枣阳市| 岢岚县| 镇安县| 盈江县| 罗江县| 灵寿县| 阳曲县| 涿州市| 津市市| 南岸区| 黄大仙区| 闵行区| 博爱县| 长武县| 治县。| 荆州市| 黑河市| 左权县| 宜川县| 辽阳市| 陕西省| 将乐县| 镇康县| 铁岭市| 舒兰市| 丹东市| 岳阳县| 林州市| 开远市| 什邡市| 泌阳县| 永州市| 靖宇县| 全州县| 桃源县| 玉门市| 霍山县| 平顺县| 宜章县|