时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M 热度指数:521803
本题知识点: 栈
题目描述
定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))。
let arr = []
function push(node)
{
// write code here
arr.push(node)
}
function pop()
{
// write code here
arr.pop()
}
function top()
{
// write code here
return arr[arr.length-1]
}
function min()
{
// write code here
return Math.min(...arr)
}