Javascript solution


  • 0
    E
    var Queue = function() {
        this.member = [];
    };
    
    Queue.prototype.push = function(x) {
        this.member.push(x);
    };
    
    Queue.prototype.pop = function() {
        this.member.shift();
    };
    
    Queue.prototype.peek = function() {
        return this.member[0];
    };
    
    Queue.prototype.empty = function() {
        return this.member.length === 0;
    };
    

Log in to reply
 

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