π¬Β λ¬Έμ
https://app.codility.com/programmers/lessons/7-stacks_and_queues/stone_wall/
π¬Β νμ΄
publicfunc solution(_ H :inout[Int])->Int{varstack:[Int]=[]varcnt=0forhin 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/
π¬Β λ¬Έμ https://app.codility.com/programmers/lessons/7-stacks_and_queues/stone_wall/
π¬Β νμ΄μμμκ°:μκ° λ³΅μ‘λ: O(N)νκ°ν: https://app.codility.com/demo/results/trainingYWMQ8V-GRQ/