* @lc app=leetcode id=232 lang=javascript
* [232] Implement Queue using Stacks
* Initialize your data structure here.
var MyQueue = function () {
// tag: queue stack array
* Push element x to the back of queue.
MyQueue.prototype.push = function (x) {
while ((cur = this.stack.pop())) {
this.helperStack.push(cur);
this.helperStack.push(x);
while ((cur = this.helperStack.pop())) {
* Removes the element from in front of queue and returns that element.
MyQueue.prototype.pop = function () {
MyQueue.prototype.peek = function () {
return this.stack[this.stack.length - 1];
* Returns whether the queue is empty.
MyQueue.prototype.empty = function () {
return this.stack.length === 0;
* Your MyQueue object will be instantiated and called as such:
* var obj = new MyQueue()
* var param_2 = obj.pop()
* var param_3 = obj.peek()
* var param_4 = obj.empty()