728x90
정답
def solution(k, score):
answer = []
scoreList = []
for i in score:
scoreList.append(i)
if len(scoreList) <= k:
answer.append(min(scoreList))
else:
scoreList.sort(reverse = True)
answer.append(scoreList[k-1])
return answer
명예의 전당의 수보다 사람의 수가 적을때는 가장 작은 점수를 answer에 담고, 사람의 수가 k보다 크면 새로운 리스트에 저장하여 역으로 정렬 후에 k-1번째(인덱스는 0부터 시작함으로)를 answer에 담았습니다.
728x90
'프로그래머스 코딩테스트 > Python' 카테고리의 다른 글
프로그래머스 모의고사 Python (0) | 2024.06.28 |
---|---|
프로그래머스 과일 장수 Python (0) | 2024.06.28 |
프로그래머스 카드 뭉치 Python (0) | 2024.06.26 |
프로그래머스 2016년 Python (0) | 2024.06.26 |
프로그래머스 콜라문제 python (0) | 2024.06.26 |