Growth Hoon

20231027_TIL_프로그래머스 본문

TIL_Today I Learned

20231027_TIL_프로그래머스

sayhoon 2023. 10. 31. 19:58

명예의 전당(1)

def solution(k, scores):
    answer = []
    hof = []
    for score in scores:
        if len(hof) >= k:
            if min(hof) > score: # 명예의 전당에서 최소값이 더 큰 경우
                answer.append(min(hof))
            else: # 명예의 전당에서 최소값이 더 작은 경우
                min_index = hof.index(min(hof))
                del hof[min_index]
                hof.append(score)
                answer.append(min(hof))
                
        else:
            hof.append(score)
            answer.append(min(hof))
                

        
            
    return answer