Leetcode506

 

9比他大的只有10 排第二

3比他大的有 10  8 9 4

 

 暴力解法 遍历一遍 

       Map<Integer,String>map = new HashMap<Integer,String>();
        for(int i =0;i<score.length;i++ ){
            //排第一位的
            int biggerNum=0;
            for(int j=0;j<score.length;j++){
                if(score[i]<score[j]){
                    biggerNum++;
                }
            }
            String index = String.valueOf(biggerNum+1);
            index= "1".equals(index)?"Gold Medal":index;
            index= "2".equals(index)?"Silver Medal":index;
            index= "3".equals(index)?"Bronze Medal":index;
            map.put(i,index);
        }

        return  map.values().toArray(new String[0]);
    

nlogn解法:

暂未写出

 

posted @ 2021-12-05 17:38  天道酬勤312  阅读(16)  评论(0)    收藏  举报