Notice
Recent Posts
Recent Comments
Link
250x250
반응형
DecordRay
[프로그래머스] Level1 : 푸드 파이트 대회[Python] 본문
728x90
반응형
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/138477
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이 :
1. 명예의 전당리스트 honor_list 생성
2. k일 이전인지 이후인지에 따라 조건문 분기
- k일까지 : honor_list에 score[i] 추가
- k일 이후 : honor_list[0](최솟값)이 score[i] 보다 작을 경우 honor_list에서 honor_list[0] 삭제 후 score[i] 추가
3. honor_list 오름차순 정렬 후 answer에 honor_list[0](최솟값) 추가
코드 :
def solution(k, score):
answer = []
honor_list = []
for i in range(len(score)):
if len(answer) < k:
honor_list.append(score[i])
else:
if honor_list[0] < score[i]:
honor_list.pop(0)
honor_list.append(score[i])
honor_list.sort()
answer.append(honor_list[0])
return answer
728x90
반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level1 : 기사단의 무기[Python] (0) | 2023.02.03 |
---|---|
[프로그래머스] Level1 : 숫자 짝꿍[Python] (0) | 2023.02.03 |
[프로그래머스] Level1 : 과일 장수[Python] (0) | 2023.02.02 |
[프로그래머스] Level1 : 가장 가까운 같은 글자[Python] (0) | 2023.02.02 |
[프로그래머스] Level1 : 푸드 파이트 대회[Python] (0) | 2023.02.02 |
Comments