일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- join
- coding
- 코테
- Stack
- counter
- mysql
- time complexity
- 코딩테스트
- coding test
- import re
- 조합
- CodingTest
- sql
- lv4
- BFS
- Level2
- itertools
- programmers
- 시간복잡도
- 프로그래머스
- 파이썬
- collections
- 코딩
- lambda
- 완전탐색
- python
- level4
- 데이터분석
- Queue
- 연습문제
- 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
'Algorithm > 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 |