문제 풀이/Programmers

[python3][level 2] H-Index

[잉간] 2019. 4. 14. 22:05


입력받은 리스트의 길이 citations부터 0까지 반복문을 실행한다.

citations의 요소 number와 h를 비교해 number가 h 이상일 때 count를 1 증가시킨다. 

만약 count가 h 이상이면 h를 반환한다. 반복문이 모두 종료되어도 반환되는 값이 없으면 0을 반환한다.

문제풀이

def solution(citations):
    for h in range(len(citations), 0, -1):
        count = 0
        for number in citations:
            if number >= h:
                count += 1
        if count >= h:
            return h
    return 0