云计算百科
云计算领域专业知识百科平台

Leetcode 155. 最小栈 (Day 24) JavaScript

var MinStack = function() {
this.stack=[[1,Infinity]];

};

/**
* @param {number} val
* @return {void}
*/

MinStack.prototype.push = function(val) {
this.stack.push([val,Math.min(val,this.getMin())]);
};

/**
* @return {void}
*/

MinStack.prototype.pop = function() {
this.stack.pop();
};

/**
* @return {number}
*/

MinStack.prototype.top = function() {
return this.stack[this.stack.length1][0];
};

/**
* @return {number}
*/

MinStack.prototype.getMin = function() {
return this.stack[this.stack.length1][1];
};

/**
* Your MinStack object will be instantiated and called as such:
* var obj = new MinStack()
* obj.push(val)
* obj.pop()
* var param_3 = obj.top()
* var param_4 = obj.getMin()
*/

赞(0)
未经允许不得转载:网硕互联帮助中心 » Leetcode 155. 最小栈 (Day 24) JavaScript
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!