일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- programmers
- itertools
- mysql
- lambda
- Level2
- Queue
- sql
- time complexity
- 코딩테스트
- level4
- coding
- 코딩
- python
- 파이썬
- 완전탐색
- join
- 조합
- 코테
- AARRR
- 프로그래머스
- tableau
- import re
- lv4
- Growth hacking
- coding test
- counter
- hackerrank
- collections
- cte
- Stack
Archives
- Today
- Total
ror_coding
[Programmers] H-Index - 42747 본문
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
'Coding Test > Python' 카테고리의 다른 글
[Programmers] 의상 - 42578 (2) | 2024.12.02 |
---|---|
[Python] Stack, Queue (collections) (deque) (0) | 2024.12.02 |
[Programmers] n^2 배열 자르기 - 87390 (0) | 2024.11.01 |
[Programmers] 연속 부분 수열 합의 개수 - 131701 (0) | 2024.11.01 |
[Programmers] 예상 대진표 - 12985 (0) | 2024.10.31 |