import Foundation
func solution(_ numbers:[Int]) -> [Int] {
var answer: [Int] = Array(repeating: -1, count: numbers.count)
var stack: [(Int, Int)] = []
for (i, num) in numbers.enumerated() {
if !stack.isEmpty {
while !stack.isEmpty && stack.last!.1 < num {
answer[stack.last!.0] = num
stack.popLast()
}
}
stack.append((i, num))
}
return answer
}
stack 사용해서 시간복잡도 단축