chyam

[프로그래머스 Lv2, python]- H-index 본문

프로그래머스/LV2

[프로그래머스 Lv2, python]- H-index

chyam_eun 2025. 1. 9. 10:43

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

def solution(cit):
    answer=0
    cit.sort()
    le=len(cit)
    h=0 # 인덱스
    while(h<cit[-1]): #-1보다 작을때
        for i in range(le):
            if(cit[i]>=h and le-i>=h): # 값이 h 이상이고 개수가 h이상일때
                answer=h
        h+=1
    return answer

위는 처음 내 풀이이고, 아래는 다른분의 간단한 풀이이다.

내 풀이는 시간복잡도가 조금 있어서 아래와같이 하는것이 좋을것같다.

def solution(citations):
    citations = sorted(citations)
    l = len(citations)
    for i in range(l):
        if citations[i] >= l-i:
            return l-i
    return 0