博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leedcode 155] Min Stack
阅读量:4363 次
发布时间:2019-06-07

本文共 645 字,大约阅读时间需要 2 分钟。

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

  • push(x) -- Push element x onto stack.
  • pop() -- Removes the element on top of the stack.
  • top() -- Get the top element.
  • getMin() -- Retrieve the minimum element in the stack.
    class MinStack {    //使用两个栈,一个正常使用,一个保存已经压栈中最小的数,每次push和pop注意两个栈同时操作    private Stack
    min=new Stack
    (); private Stack
    stack=new Stack
    (); public void push(int x) { stack.push(x); if(min.empty()||x

     

转载于:https://www.cnblogs.com/qiaomu/p/4694797.html

你可能感兴趣的文章
常用激活函数(激励函数)理解与总结
查看>>
DataFrame.to_dict(orient='dict')英文文档翻译
查看>>
DictVectorizer中的fit_transform
查看>>
HDFS优缺点
查看>>
排序算法(1) 快速排序 C++实现
查看>>
伙伴分配器的一个极简实现
查看>>
$.ajax所犯的错误。success后面不执行
查看>>
Spring注入方式及注解配置
查看>>
cocos2dx blender 骨骼动画实现
查看>>
ARM基础
查看>>
eclipse
查看>>
Mybatis参数传递及返回类型
查看>>
关于Ubuntu使用笔记
查看>>
调整Tomcat上的参数提高性能[转]
查看>>
在Ajax方式产生的浮动框中,点击选项包含某个关键字的选项
查看>>
SDK 操作 list-view control 实例 -- 遍历进程
查看>>
由于SSH配置文件的不匹配,导致的Permission denied (publickey)及其解决方法
查看>>
65. Valid Number
查看>>
检查MySQL主从数据一致性
查看>>
结构化日志:出错时你最想要的好朋友
查看>>