fun rankArray(unranked: Array<Int>): Array<Int> {
val sorted = unranked.sortedArrayDescending() //create a temp array sortest from greatest to least
val final = ArrayList<Int>() //create a arraylist because it's expandable
for(element in unranked) final.add(sorted.indexOf(element) + 1) //add to the list the ranking from greatest to least in the same order as the data originally was
return final.toTypedArray() //return result as array not arraylist
}
2条答案
按热度按时间5uzkadbs1#
试试这样的方法:
nmpmafwu2#
创建一个类
然后粘贴此代码
输出:[1,5,3,4,2]