https://school.programmers.co.kr/learn/courses/30/lessons/131704?language=swift
1. Swift 풀이
import Foundation
func solution(_ order:[Int]) -> Int {
let n = order.max()!
var p = 0
var container = [Int]()
var answer = 0
for i in 1...n {
container.append(i)
while p < order.count && container.last == order[p] {
answer += 1
container.removeLast()
p += 1
}
}
return answer
}
2. Python 풀이
def solution(order):
n = max(order)
p = 0
container = []
answer = 0
for i in range(1,n+1):
container.append(i)
while p < len(order) and len(container) > 0 and order[p] == container[-1]:
answer += 1
p += 1
container.pop()
return answer
[프로그래머스] 기지국 설치 (0) | 2024.01.18 |
---|---|
[프로그래머스] 숫자 게임 (0) | 2024.01.17 |
[프로그래머스] 오픈채팅방 (0) | 2024.01.10 |
[프로그래머스] 롤케이크 자르기 (0) | 2024.01.09 |
[프로그래머스] 스킬트리 (1) | 2024.01.08 |