⭐ 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/138477
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
⭐ 풀이 코드
방법 1
def solution(k, score):
answer = []
hall = []
for s in score:
hall.append(s)
hall.sort(reverse=True)
answer.append(min(hall[:k]))
return answer
방법 2
def solution(k, score):
answer = []
rank = []
for s in score:
if len(rank) == k:
if rank[-1] < s:
rank[-1] = s
else:
rank.append(s)
rank.sort(reverse=True)
answer.append(rank[-1])
return answer
'Python > Programmers' 카테고리의 다른 글
[프로그래머스/Python] Lv 2. [3차] 압축 (0) | 2023.04.16 |
---|---|
[프로그래머스/Python] Lv 1. 추억 점수 (0) | 2023.04.16 |
[프로그래머스/Python] Lv 1. 과일 장수 (0) | 2023.04.16 |
[프로그래머스/Python] Lv 2. 2 x n 타일링 (0) | 2023.04.15 |
[프로그래머스/Python] Lv 2. 방문길이 (0) | 2023.04.15 |