IT/알고리즘
[프로그래머스] 귤 고르기
남갯
2024. 9. 26. 16:41
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/138476?language=kotlin
@Test
fun solution() {
val k: Int = 6
val tangerine: IntArray = intArrayOf()
var answer: Int = 0
val map = mutableMapOf<Int, Int>()
for (i in tangerine.indices) {
map[tangerine[i]] = map.getOrDefault(tangerine[i], 0) + 1
}
var result = k
for (i in map.values.sortedDescending()) {
if(result > 0) {
result -= i
answer ++
}
}
return
}
LIST