Implement Stack using Queues LeetCode solution in JavaScript

1
var MyStack = function () {
2
this.stack = [];
3
};
4

5
/**
6
* @param {number} x
7
* @return {void}
8
*/
9
MyStack.prototype.push = function (x) {
10
this.stack.push(x);
11
};
12

13
/**
14
* @return {number}
15
*/
16
MyStack.prototype.pop = function () {
17
return this.stack.splice([this.stack.length - 1], 1);
18
};
19

20
/**
21
* @return {number}
22
*/
23
MyStack.prototype.top = function () {
24
return this.stack[this.stack.length - 1];
25
};
26

27
/**
28
* @return {boolean}
29
*/
30
MyStack.prototype.empty = function () {
31
return this.stack.length === 0 ? true : false;
32
};
33

34
/**
35
* Your MyStack object will be instantiated and called as such:
36
* var obj = new MyStack()
37
* obj.push(x)
38
* var param_2 = obj.pop()
39
* var param_3 = obj.top()
40
* var param_4 = obj.empty()
41
*/

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0