Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 혼공머신
- 혼공학습단
- 모델링
- 포스코 청년
- Brightics Studio
- 데이터분석
- Brigthics를 이용한 분석
- 삼성SDS Brigthics
- 개인 의료비 예측
- 노코드AI
- 삼성SDS
- 혼공머신러닝딥러닝
- 삼성SDS Brightics
- 포스코 아카데미
- 추천시스템
- 브라이틱스 서포터즈
- 팀 분석
- 삼성 SDS
- 삼성 SDS Brigthics
- Brightics
- 영상제작기
- 캐글
- 직원 이직여부
- Brightics를 이용한 분석
- Brigthics
- 데이터 분석
- 혼공
- Brigthics Studio
- 브라이틱스
- 직원 이직률
Archives
- Today
- Total
데이터사이언스 기록기📚
[프로그래머스] Level 2_H-Index(정렬) 본문
📌문제 유형
정렬
📌문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
📌나의 문제풀이
1차 시도(87.5)
def solution(citations):
answer,h = 0,1
num_index = []
citations.sort(reverse = True)
num_index.append(h)
for i in range(1, len(citations)-1):
h += 1
num_index.append(h)
if num_index[i] >= citations[i+1]:
answer = num_index[i]
break
return answer
2차 시도(통과, +11)
- num_index : n번 이상 인용된 횟수
- citations 내림차순 정렬
- num_index[i]와 citations[i+1]을 비교, citations[i+1]가 num_index[i]이하 인용되었다면 num_index[i]는 h
(어떤 과학자가 발표한 논문 n편 중, h번 이상 인용된 논문이 h편 이상이고 나머지 논문이 h번 이하 인용되었다면) - 인용 횟수가 다 같은 경우 : num_index의 마지막값 리턴
(인용 횟수가 모두 0일 때, 0 리턴)
def solution(citations):
answer,h = 0,0
num_index = [i+1 for i in range(len(citations))]
citations.sort(reverse = True)
# num_index[i]와 citations[i+1]을 비교, num_index[i] 값이 크면 answer로 리턴
for i in range(0, len(citations)-1):
if num_index[i] >= citations[i+1]:
answer = num_index[i]
break
# [5,5,5] return 3인 경우
if citations[-1] >= num_index[-1]:
return num_index[-1]
# [0,0,0] return 0인 경우
elif citations[0] == 0:
return 0
return answer
📌다른사람의 문제 풀이
1)
1) min(index,value) 부분은 가능할 수 있는 모든 h-index를 추출하는 부분
2) max(~) 값은 가능할 수 있는 모든 h-index 중 가장 큰 값을 추출하는 부분.
예를들어 [6, 5, 4, 1, 0]의 경우에선 min~ 부분은 min(1, 6), min(2, 5), min(3, 4), min(4, 1), min(5, 0), 즉 해당 인용수 이상의 논문개수와 해당 논문의 인용수 중 더 작은 숫자를 고르는 작업을 하고(h-index로 가능한 숫자 추출), max~부분은 앞에서 골라진 (1, 2, 3, 1, 0) 중 가장 큰 숫자를 뽑아 실제 h-index를 구하는 방법
출처 : https://school.programmers.co.kr/learn/courses/30/lessons/42747/solution_groups?language=python3
def solution(citations):
citations.sort(reverse=True)
answer = max(map(min, enumerate(citations, start=1)))
return answer
2)
def solution(citations):
citations = sorted(citations)
l = len(citations)
for i in range(l):
if citations[i] >= l-i:
return l-i
return 0
📌리뷰
- 문제 제대로 이해하기
- 이외의 경우의 수 생각해보기
728x90
'Coding Test > 프로그래머스(Python)' 카테고리의 다른 글
[프로그래머스] Level2_전화번호 목록(해시) (0) | 2022.09.24 |
---|---|
[프로그래머스] Level2_위장(해시) (0) | 2022.09.24 |
[프로그래머스] Level 2_가장 큰 수(정렬) (0) | 2022.09.20 |
[프로그래머스] Level 2_다리를 지나는 트럭(스택/큐) (0) | 2022.09.17 |
[프로그래머스] Level 2_올바른 괄호(스택/큐) (0) | 2022.09.08 |
Comments