문제링크
풀이1
class Solution {
fun findRelativeRanks(score: IntArray): Array<String> {
val answer = Array(score.size) { "" }
val pq = PriorityQueue<Pair<Int, Int>>( { a, b -> b.first - a.first })
score.forEachIndexed { index, it ->
pq.offer(Pair(it, index))
}
repeat(score.size) { it ->
val temp = pq.poll()
when (it + 1) {
1 -> answer[temp.second] = "Gold Medal"
2 -> answer[temp.second] = "Silver Medal"
3 -> answer[temp.second] = "Bronze Medal"
else -> answer[temp.second] = (it + 1).toString()
}
}
return answer
}
}