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解法:
暂未写出
写博客是为了让别人能明白,之后在是自己明白. 如果有不明白的地方欢迎加Q3378404370 讨论