Coding Test/Python
[Programmers] H-Index - 42747
ro_rdil_31
2024. 12. 2. 14:55
728x90
enumerate( a, start = 1) 로 index 시작 정하기 !
Question
H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다.
어떤 과학자가 발표한 논문 n편 중, h번 이상 인용된 논문이 h편 이상이고 나머지 논문이 h번 이하 인용되었다면 h의 최댓값이 이 과학자의 H-Index입니다.
어떤 과학자가 발표한 논문의 인용 횟수를 담은 배열 citations가 매개변수로 주어질 때, 이 과학자의 H-Index를 return 하도록 solution 함수를 작성해주세요.
Point
- enumerate에서 start = 1를 이용하여 index를 0이 아닌 1부터 시작.
- sort된 list를 이용하여 if 문 지우기.
Code 1
def solution(citations):
result = 0
citations.sort(reverse=True)
for idx, i in enumerate(citations, start = 1):
# cnt = sum(1 for j in citations if j >= i)
result = max(result, min(i, idx))
return result
Code 2
def solution(citations):
result = 0
citations.sort(reverse=True)
answer = max(map(min, enumerate(citations, start=1)))
return answer

Now me
On my github
728x90