Min Stack - LeetCode
Can you solve this real interview question? Min Stack - Design a stack that supports push, pop, top, and retrieving the…leetcode.com 領500元現金了嗎? 點選我的連結成功開樂天帳戶+登入樂天網銀APP,拿500元現金! 樂天帳戶好康在這 : · 使用行動支付5次,享次月活儲年息1.35%存額無上限 · VIP享每月免費跨提/轉共16次 · 提領日幣手續費優惠8次/月 (推薦序號: JGONGL) 樂天國際銀行 - 日本純網銀領導品牌
手機開戶最快只要10分鐘!2023年3月31號前只要月月行動支付滿5次,次月就享活儲年利率1.35%,存款額度無上限!…www.rakuten-bank.com.tw var MinStack = function() {
this.items = []
};
/**
* @param {number} val
* @return {void}
*/
MinStack.prototype.push = function(val) {
this.items.push({
value: val,
min: this.items.length === 0 ? val : Math.min(val, this.getMin()),
});
};
/**
* @return {void}
*/
MinStack.prototype.pop = function() {
this.items.pop()
};
/**
* @return {number}
*/
MinStack.prototype.top = function() {
return this.items[this.items.length - 1].value
};
/**
* @return {number}
*/
MinStack.prototype.getMin = function() {
return this.items[this.items.length - 1].min
};