본문 바로가기

알고리즘/프로그래머스

[Python] H-index

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

  • 첫 번째 풀이(틀림)
# H-index
def solution(citations):
    citations.sort()
    answer = []
    
    for i in range(len(citations)):
        
        if len(citations) - i  <= citations[i] :
            
            answer.append(len(citations)-i)
            
    return max(answer)

 

  • 다른 사람의 풀이(정답)
def solution(citations):

    citations.sort()
    for idx , citation in enumerate(citations):
    
        if citation >= len(citations) - idx :
            return len(citations) - idx
    return 0

비슷하지만 만족하는 idx가 없을 때 0을 리턴하는 부분이 다름.

 

아마 이 부분에서 틀리지 않았나 생각함.

 

'알고리즘 > 프로그래머스' 카테고리의 다른 글

[Python] 캐시  (0) 2022.11.30
[Python] 2016년  (0) 2022.11.29
[Python] 멀리 뛰기  (0) 2022.11.27
[Python] 점프와 순간 이동  (0) 2022.11.26
[Python] 두 개 뽑아서 더하기  (0) 2022.11.24