JavaScript Solution beats 97.96%


  • -1
    V

    Didn't do much...

    /**
     * @constructor
     */
    var Queue = function() {
        this.stack = [];
    };
    
    /**
     * @param {number} x
     * @returns {void}
     */
    Queue.prototype.push = function(x) {
        this.stack.push(x);
    };
    
    /**
     * @returns {void}
     */
    Queue.prototype.pop = function() {
        this.stack.shift();
    };
    
    /**
     * @returns {number}
     */
    Queue.prototype.peek = function() {
        return this.stack[0];
    };
    
    /**
     * @returns {boolean}
     */
    Queue.prototype.empty = function() {
        return this.stack.length === 0;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.