题解 | #包含min函数的栈#
包含min函数的栈
https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
let stack = [] function push(node) { stack.push(node) } function pop() { if(stack.length===0) return false return stack.pop() } function top() { if(stack.length===0) return false return stack[stack.length-1] } function min() { if(stack.length===0) return false let min = stack[0] for(let i=0;i<stack.length;i++){ if(min>stack[i]) min=stack[i] } return min } module.exports = { push : push, pop : pop, top : top, min : min };