정수 내림차순으로 배치하기

두주·2023년 12월 20일

코드카타

목록 보기
10/19

class Solution {
    fun solution(n: Long): Long {
        val strvalue = n.toString().map { it }
        
        val answer = strvalue.sortedDescending().joinToString("")
        
        return answer.toLong()
    }
}

.map { it } 을 통해 리스트 형식으로 저장할 수 있다는 것을 알게되었다.
sortedDescending이나 joinToString도 처음 보는 함수였다.

map에 대해서는 추가 공부가 필요할 듯 하다.

profile
야옹.

0개의 댓글