728x90

H-Index

 

문제 설명

H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다.

 

어떤 과학자가 발표한 논문 n편 중, h번 이상 인용된 논문이 h편 이상이고 나머지 논문이 h번 이하 인용되었다면 h의 최댓값이 이 과학자의 H-Index입니다.

 

어떤 과학자가 발표한 논문의 인용 횟수를 담은 배열 citations가 매개변수로 주어질 때, 이 과학자의 H-Index를 return 하도록 solution 함수를 작성해주세요.

 

제한사항

과학자가 발표한 논문의 수는 1편 이상 1,000편 이하입니다.

논문별 인용 횟수는 0회 이상 10,000회 이하입니다.

입출력 예

citations return

[3, 0, 6, 1, 5] 3

입출력 예 설명

이 과학자가 발표한 논문의 수는 5편이고, 그중 3편의 논문은 3회 이상 인용되었습니다. 그리고 나머지 2편의 논문은 3회 이하 인용되었기 때문에 이 과학자의 H-Index는 3입니다.

 

※ 공지 - 2019년 2월 28일 테스트 케이스가 추가되었습니다.

 

https://en.wikipedia.org/wiki/H-index "위키백과" ↩ 

 

처음 실패 답

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def solution(citations):
    answer = 0
    cnt = 0
    
    for i in citations:
        if i<=answer:
            continue
        for j in range(len(citations)):
            if i<=citations[j]:
                cnt+=1
        else:
            if i==cnt:
                answer = i
    
    return answer
cs

 

 

내 성공한 답

 

1
2
3
4
5
6
7
8
9
10
11
12
13
def solution(citations):
    citations.sort(reverse=True)
    
    for i in range(citations[0],0,-1):
        cnt = 0
        for j in range(len(citations)):
            if i<=citations[j]:
                cnt+=1
        else:
            if i<=cnt:
                return i
    else:
        return 0
cs

 

남의 답 1

 

1
2
3
4
def solution(citations):
    citations.sort(reverse=True)
    answer = max(map(min, enumerate(citations, start=1)))
    return answer
cs

 

 

남의 답 2

 

1
2
3
4
5
6
7
def solution(citations):
    citations = sorted(citations)
    l = len(citations)
    for i in range(l):
        if citations[i] >= l-i:
            return l-i
    return 0
cs

 

 

남의 답 3

 

1
2
3
4
5
6
def solution(citations):
  sorted_citations = sorted(citations, reverse=True)
  for i in range(len(sorted_citations)):
    if sorted_citations[i] <= i: 
      return i
  return len(sorted_citations)
cs

 

 

남의 답 4

 

1
2
3
4
5
6
7
8
9
10
11
def counting(l, n):
    return len(list(filter(lambda x: x >= n, l)))
 
def solution(citations):
    answer = 0
    for i in range(max(citations)):
        if counting(citations, i) >= i:
            answer = i
        else:
            break
    return answer
cs

 

 

남의 답 5

 

1
2
3
4
5
6
7
8
def solution(citations):
    citations.sort()
    n, answer = len(citations), 0
    for i, cites in enumerate(citations):
        h = n - i
        if cites >= h:
            return h
    return
cs

 

 

남의 답 6

 

1
2
3
4
5
def solution(citations: list):
    for i in range(1len(citations) + 1):
        list_temp = citations.copy()
        list_temp = list(filter(lambda x:x > i, list_temp))
        if i == len(list_temp): return i
cs

 

 

남의 답 7

 

1
2
3
4
5
6
7
8
9
10
11
12
13
import heapq
def solution(citations):
    n = len(citations)
    heap = list(citations)
    heapq.heapify(heap)
    num = 0
    while heap:
        m = n - num
        now = heapq.heappop(heap)
        if now >= m:
            return m
        num += 1
    return 0
cs

 

 

남의 답 8

 

1
2
3
4
5
6
7
8
9
10
11
def solution(citations):
    citations.sort(reverse=True)
    max_h = len(citations)
 
    for i in range(max_h, -1-1):
        higher = sum(map(lambda n: n > i, citations))
        same = sum(map(lambda n: n == i, citations))
        if higher + same >= i:
            return i
 
    return 0
cs

 

 

남의 답 9

 

1
2
3
4
5
6
7
def solution(citations):
    citations.sort(reverse=True)
    h_index = 0
    for c in citations:
        if c > h_index:
            h_index += 1
    return h_index
cs

 

 

1239점 + 7점 -> 1246점

 

 

드디어 만 등 안

728x90
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기