[프로그래머스] 과일 장수(Kotlin)

0

프로그래머스

목록 보기
95/127
post-thumbnail

[프로그래머스] 과일 장수(Kotlin)

풀이

import kotlin.math.*

class Solution {
    fun solution(k: Int, m: Int, score: IntArray): Int {
        var answer: Int = 0
        
        //score 내림차순 정렬
        var sortedScore = score.sorted().reversed()
        
        var index = 0
        while(index + m - 1 < score.size){
            answer += (m * sortedScore[index + m - 1])
            index += m
        }
        
        return answer
    }
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글