https://school.programmers.co.kr/learn/courses/30/lessons/138477
1. Swift 풀이
func solution(_ k:Int, _ score:[Int]) -> [Int] {
var answer = [Int]()
var board = [Int]()
for s in score {
if board.count < k {
board.append(s)
}
else if board.last! < s {
board[k-1] = s
}
board.sort(by: >)
answer.append(board.last!)
}
return answer
}
2. Python 풀이
def solution(k, score):
answer = []
board = []
for s in score:
if len(board) < k :
board.append(s)
elif board[-1] < s:
board[k-1] = s
board.sort(reverse=True)
answer.append(board[-1])
return answer
[프로그래머스] 실패율 (0) | 2024.03.22 |
---|---|
[프로그래머스] 덧칠하기 (0) | 2024.03.21 |
[프로그래머스] 콜라 문제 (0) | 2024.03.13 |
[프로그래머스] 마법의 엘레베이터 (0) | 2024.03.11 |
[프로그래머스] 최소 직사각형 (0) | 2024.03.08 |