Description
Implement a first-in-first-out (FIFO) queue using only two stacks. The implemented queue should support push, pop, peek, and empty operations. Return the result as a string.
Examples
Input:
["MyQueue", "push", "push", "peek", "pop", "empty"] with [[], [1], [2], [], [], []]Output:
[null, null, null, 1, 1, false]Explanation:
The result is [null, null, null, 1, 1, false].
Input:
["MyQueue", "push", "push", "push", "pop", "peek", "pop", "pop", "empty"]Output:
[null, null, null, null, 3, 4, 4, 5, true]Explanation:
The result is [null, null, null, null, 3, 4, 4, 5, true].
Input:
["MyQueue", "push", "pop", "push", "push", "peek", "push", "pop", "pop", "empty"]Output:
[null, null, 7, null, null, 8, null, 8, 9, false]Explanation:
Initialize queue, push 7 then immediately pop it (returns 7). Push 8 and 9, peek shows 8. Push 6, then pop twice getting 8 and 9. Queue still contains 6 so not empty.
Constraints
- •
1 ≤ x ≤ 9 - •
At most 100 calls will be made to push, pop, peek, and empty.