Stack Using Single Queue

Implement a stack using a single queue. Your implementation should support the following operations:

  • push(value) - Push element onto stack
  • pop() - Remove element from stack
  • top() - Get the top element
  • isEmpty() - Check if stack is empty

All operations should run in O(1) time complexity.

Examples
Input: [["Solution","push","push","pop","top"],[[],[1],[2],[],[]]]
Output: [null,null,null,2,1]
Hints

Stack Using Single Queue

Implement a stack using a single queue. Your implementation should support the following operations: