[프로그래머스]H-Index(Python)

2022. 8. 23. 17:55·CodingTest/Programmers

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
'CodingTest/Programmers' 카테고리의 다른 글
  • [프로그래머스]성격 유형 검사하기(Python)
  • [프로그래머스]124 나라의 숫자(Python)
  • [프로그래머스]멀쩡한 사각형(Python)
  • [프로그래머스]오픈채팅방(Python)
iihye_
iihye_
  • iihye_
    hye-log
    iihye_
    • 분류 전체보기 (293)
      • Development (17)
        • Spring (3)
        • Python (5)
        • JavaScript (4)
        • React (4)
        • Next.js (1)
      • Infra (15)
        • Docker (1)
        • Jenkins (2)
        • Nginx (3)
        • JBoss (1)
        • Windows (3)
        • Linux (3)
        • Kafka (2)
      • Database (1)
        • MongoDB (1)
      • Tools (1)
        • Git (0)
        • Github (1)
      • CodingTest (125)
        • Programmers (38)
        • Baekjoon (52)
        • SWEA (27)
        • Jungol (4)
        • Codetree (1)
        • Goorm (3)
      • Education (99)
        • SSAFY 10기 (5)
        • AI Tech 4기 (94)
      • NomadCoder (35)
        • (JS)크롬 앱 만들기 (35)
      • Notice (0)
  • 링크

    • Github
  • 인기 글

  • 최근 글

  • 전체
    오늘
    어제
  • hELLO· Designed By정상우.v4.10.5
iihye_
[프로그래머스]H-Index(Python)
상단으로

티스토리툴바