공부 서랍장/알고리즘 공부

[프로그래머스] H-Index python

만땅이 2022. 9. 18. 19:24

문제: https://school.programmers.co.kr/learn/courses/30/lessons/42747

처음에 풀때 테스트9번이 실패했는데 [4, 4, 4] 일 경우를 생각해보면 된다

def solution(citations):
    answer = 0
    citations = sorted(citations,reverse=True)
    
    
    for index,i in enumerate(citations):
        if i < (index + 1):
            answer = index
            break
            
    if citations[-1] > len(citations):
        answer = len(citations)
            
    return answer
반응형