본문 바로가기

IT/알고리즘

[프로그래머스] 귤 고르기

728x90
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 
}

 

728x90
LIST