๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/Kotlin

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค • ์ฝ”ํ‹€๋ฆฐ] ๋ช…์˜ˆ์˜ ์ „๋‹น(1) #138477

by ํ‚ค์œค 2023. 12. 14.

#138477

๐ŸŽ„ Question ?

https://school.programmers.co.kr/learn/courses/30/lessons/138477#

 

 

๐ŸŽ€ Answer

class Solution {
    fun solution(k: Int, score: IntArray): IntArray {        
        var list = mutableListOf<Int>()
        var answer = mutableListOf<Int>()
        for (i in score.indices) {
            list.add(score[i])
            list.sort()
            if (i<k-1) {
                answer.add(list[0])
            } else {
                answer.add(list[i-k+1])
            }
        }
        return answer.toIntArray()
    }
}

 

๐ŸŽ Result

๐Ÿ† Comment

ํ’€๋•Œ ๋งˆ๋‹ค ๋ฟŒ๋“ฏ