var stack = [];
function push(node)
{
// write code here
stack.push(node);
}
function pop()
{
// write code here
return stack.pop();
}
function top()
{
// write code here
return stack[stack.length - 1];
}
function min()
{
// write code here
// 或者使用 ES6 语法 Math.min(...stack)
return Math.min.apply(null, stack);
}
算法之定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))
最新推荐文章于 2022-03-28 17:27:32 发布