알고리즘/프로그래머스
[Python] H-index
dding96
2022. 11. 28. 10:17
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을 리턴하는 부분이 다름.
아마 이 부분에서 틀리지 않았나 생각함.