https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/
func validateStackSequences(_ pushed: [Int], _ popped: [Int]) -> Bool {
var stack = [Int]()
var popIdx = 0
for item in pushed {
stack.append(item)
while !stack.isEmpty && (popIdx < popped.count) && stack.last == popped[popIdx] {
stack.removeLast()
popIdx = popIdx + 1
}
}
return stack.isEmpty
}