Notice
Recent Posts
Link
- Today
- Total
hye-log
[프로그래머스]H-Index(Python) 본문
0. 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/42747?language=python3
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 문제 소개
1) n 편의 논문 중 h 번 이상 인용된 논문이 h 편 이상이고
2) 나머지 논문이 h 번 이하 인용되었을 때 h 의 최댓값 구하기
2. 입출력
# input
citations = [3, 0, 6, 1, 5]
# output
return = 3
3. 코드
def solution(citations):
answer = 0
c = sorted(citations) # 정렬 (새로운 변수에 저장하기 위해서 sorted 사용)
c = list(reversed(c)) # 반대로 정렬 후 리스트화
for i in range(len(c)): # 논문 n 편 중
if c[i] >= i+1: # h 번 이상 인용된 논문이 h 편 이상이면
answer = i+1 # answer에 저장
return answer
실행 결과
4. 알게된 점
1) sort(), sorted()
변수.sort()는 변수를 정렬하고 정렬한 결과를 원래의 변수에 넣고,
sorted(변수)는 변수를 정렬하고 정렬한 결과를 새로운 변수에 넣음
sort()는 reverse=True 인자를 통해서 거꾸로 정렬을 하고,
sorted()는 reversed로 정렬한 후 list화를 해야 리스트로 결과를 얻을 수 있음
citations = [3, 0, 6, 1, 5]
# sort()
citations.sort() # [0, 1, 3, 5, 6]
citations.sort(reverse=True) # [6, 5, 3, 1, 0]
# sorted()
c = sorted(citations) # [0, 1, 3, 5, 6]
c = list(reversed(c)) # [6, 5, 3, 1, 0]
5. Github
https://github.com/iihye/Algorithm/blob/main/Programmers/h_index.py
GitHub - iihye/Algorithm
Contribute to iihye/Algorithm development by creating an account on GitHub.
github.com
728x90
'CodingTest > Programmers' 카테고리의 다른 글
[프로그래머스]성격 유형 검사하기(Python) (0) | 2022.09.06 |
---|---|
[프로그래머스]124 나라의 숫자(Python) (0) | 2022.08.26 |
[프로그래머스]멀쩡한 사각형(Python) (0) | 2022.08.19 |
[프로그래머스]오픈채팅방(Python) (0) | 2022.08.16 |
[프로그래머스]문자열 압축(Python) (0) | 2022.08.12 |
Comments