Scribbling

프로그래머스: H-Index 본문

Computer Science/Coding Test

프로그래머스: H-Index

focalpoint 2021. 10. 18. 23:24

딱 봐도 정렬 후 Binary Search하면 된다.

매번 그렇듯 프로그래머스 지문은 극혐이다.

from bisect import bisect_left

def solution(citations):
    answer = 0
    citations.sort()
    l, r = 0, citations[len(citations) - 1]
    while l <= r:
        mid = (l+r) // 2
        num = len(citations) - bisect_left(citations, mid)
        if num >= mid:
            answer = max(answer, mid)
            l = mid + 1
        else:
            r = mid - 1
    return answer