Today
Total
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
관리 메뉴

기억은 짧고 기록은 길다

[프로그래머스/Programmers] H-index - Python 본문

CodingTest/programmers

[프로그래머스/Programmers] H-index - Python

ukunV 2021. 9. 9. 12:49

Link

 

코딩테스트 연습 - K번째수

[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]

programmers.co.kr

 

Solution

def solution(citations):
    citations = sorted(citations, reverse=True)
    answer = len(citations)

    while True:
        count = 0

        for i in range(len(citations)):
            if citations[i] >= answer:
                count += 1

        if count < answer:
            answer -= 1
        else:
            return answer
🔑 key point:
    1. citations = sorted(citations, reverse=True)
    2. if count < answer: answer -= 1

 

Other Solution

def solution(citations):
    citations.sort(reverse=True)
    answer = max(map(min, enumerate(citations, start=1)))
    return answer
🔑 key point: answer = max(map(min, enumerate(citations, start=1)))
def solution(citations):
    citations = sorted(citations)
    l = len(citations)

    for i in range(l):
        if citations[i] >= l - i:
            return l - i

    return 0
🔑 key point: len(citations) - i
Comments