-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
π¬Β λ¬Έμ
https://app.codility.com/programmers/lessons/7-stacks_and_queues/stone_wall/
π¬Β νμ΄
public func solution(_ H : inout [Int]) -> Int {
var stack: [Int] = []
var cnt = 0
for h in H {
while !stack.isEmpty && stack[stack.count - 1] > h {
stack.popLast()
}
if stack.isEmpty || stack[stack.count - 1] < h {
stack.append(h)
cnt += 1
}
}
return cnt
}
μμμκ°
:
μκ° λ³΅μ‘λ
: O(N)
νκ°ν
: https://app.codility.com/demo/results/trainingYWMQ8V-GRQ/