Решение
class MyQueue {
private val inputStack = Stack<Int>()
private val outputStack = Stack<Int>()
fun push(x: Int) {
inputStack.push(x)
}
fun pop(): Int {
if (outputStack.isEmpty()) {
while (!inputStack.isEmpty()) {
outputStack.push(inputStack.pop())
}
}
return outputStack.pop()
}
fun peek(): Int {
if (outputStack.isEmpty()) {
while (!inputStack.isEmpty()) {
outputStack.push(inputStack.pop())
}
}
return outputStack.peek()
}
fun empty(): Boolean {
return inputStack.isEmpty() && outputStack.isEmpty()
}
}