Implement Queue using Stacks

Easy

Topics
StackQueueDesign

Implement a first-in-first-out (FIFO) queue using only two stacks. Implement MyQueue with push(x), pop() (removes and returns the front element), peek() (returns the front element), and empty().

Example 1

Input:  operations = ["MyQueue","push","push","peek","pop","empty"], values = [[],[1],[2],[],[],[]]
Output: [null,null,null,1,1,false]

Constraints

  • 1 <= x <= 9
  • At most 100 calls to push, pop, peek, and empty.
  • pop and peek are only called on a non-empty queue.
Run ⌘' · Submit ⌘⏎