[프로그래머스] H-Index(Kotlin)

0

프로그래머스

목록 보기
127/128
post-thumbnail
post-custom-banner

[프로그래머스] H-Index(Kotlin)

풀이

class Solution {
    fun solution(citations: IntArray): Int {
        val sortedCitations = citations.toList().sorted() 
        
        val n = sortedCitations.size 
        var h = sortedCitations.last() 
        while(h >= 0){
            val moreThanHCnt = n - sortedCitations.indexOfFirst{it >= h} 
            if(moreThanHCnt >= h) return h
            h--
        }
        return -1 //not reached
    }
}
profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글