一思路
easy题,没什么技巧,直接进行借助map确定排列顺序
二问题
三结果
public static String[] findRelativeRanks(int[] score) {
Map<Integer, String> map = new HashMap<Integer, String>();
//深拷贝浅拷贝类型 引用类型都会指向相对应的地址
int[] temp = score.clone();
//排序
Arrays.sort(temp);
for (int i = temp.length - 1; i >= 0; i--) {
if (i == temp.length - 1) {
map.put(temp[i], "Gold Medal");
} else if (i == temp.length - 2) {
map.put(temp[i], "Silver Medal");
} else if (i == temp.length - 3) {
map.put(temp[i], "Bronze Medal");
} else {
map.put(temp[i], String.valueOf(temp[i]));
}
}
String[] result = new String[score.length];
for (int i = 0; i < score.length; i++) {
result[i] = map.get(score[i]);
}
return result;
}
加油,虽然最近会很累,但是要坚持