题解 | #包含min函数的栈#
包含min函数的栈
http://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
let minValue = 10000; let stack =[] let helper =[] function push(node) { // write code here stack.push(node); if (node<=minValue){ minValue = node; helper.push(node) }else{ helper.push(helper[helper.length-1]) } } function pop() { // write code here helper.pop() return stack.pop() } function top() { // write code here return stack[ stack.length -1] } function min() { // write code here return helper[helper.length -1] } module.exports = { push : push, pop : pop, top : top, min : min };