今天做了一道MinStack的题,深深的感到自己C++还完全没有学好!!!

#include <iostream>
#include <stack>
using std::stack; class MinStack {
public:
stack<int> st;
stack<int> stm;
void push(int x)
{
st.push(x);
if(stm.empty() || stm.top()>=x)
{
stm.push(x);
}
} void pop()
{
int topElem = st.top();
st.pop();
if(topElem <= stm.top())
{
stm.pop();
} } int top()
{
return st.top();
} int getMin()
{
return stm.top();
}
};

以上是参考http://www.cnblogs.com/x1957/p/4086448.html他的代码,基本的数据结构在C++里面都有已经有了现成的代码!!!多学习!!!

LeetCode 3 :Min Stack的更多相关文章

  1. leetcode 155. Min Stack --------- java

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

  2. Java [Leetcode 155]Min Stack

    题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...

  3. leetcode 155. Min Stack 、232. Implement Queue using Stacks 、225. Implement Stack using Queues

    155. Min Stack class MinStack { public: /** initialize your data structure here. */ MinStack() { } v ...

  4. LeetCode 155 Min Stack(最小栈)

    翻译 设计支持push.pop.top和在常量时间内检索最小元素的栈. push(x) -- 推送元素X进栈 pop() -- 移除栈顶元素 top() -- 得到栈顶元素 getMin() -- 检 ...

  5. [LeetCode] 0155. Min Stack 最小栈 & C++Runtime加速

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

  6. 【LeetCode】Min Stack 解题报告

    [题目] Design a stack that supports push, pop, top, and retrieving the minimum element in constant tim ...

  7. 【leetcode】Min Stack -- python版

    题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...

  8. Java for LeetCode 155 Min Stack

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

  9. LeetCode之Min Stack 实现最小栈

    LeetCode相关的网上资源比较多,看到题目一定要自己做一遍,然后去学习参考其他的解法. 链接: https://oj.leetcode.com/problems/min-stack/ 题目描述: ...

  10. LeetCode之Min Stack

    1.原文问题描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constan ...

随机推荐

  1. C++学习003-#define 自定义宏

    C++中可以用#define来定义自定义的宏 也可以用使用#define来定义常量 但是#define只是简单的替换,在定义常量的时候没有语法检测 所以在C++定义常量可以使用  Const修饰 #d ...

  2. 自动化测试--testNG

    该文章主要介绍 testNG(testing next generation,下一代测试技术)框架的使用. 1.首先安装testNG 2.安装完成后,创建maven项目,导入TESTNG和seleni ...

  3. 分词(Tokenization) - NLP学习(1)

    自从开始使用Python做深度学习的相关项目时,大部分时候或者说基本都是在研究图像处理与分析方面,但是找工作反而碰到了很多关于自然语言处理(natural language processing: N ...

  4. 启动 SQL Server 管理 Studio 在 SQL Server 2008R2 中的错误消息:"无法读取此系统上以前注册的服务器的列表" 解决方法

    问题: 服务器被人直接停掉,重启后,发现sqlserver2008r2 启动管理器报错: "无法读取此系统上以前注册的服务器的列表" 如图: 点击继续,进入后: 解决方法: 点击上 ...

  5. nopcommerce商城系统--安装nopCommerce

    原址:http://www.nopcommerce.com/docs/79/installing-nopcommerce.aspx .NET Framework 4.5.1下载:http://www. ...

  6. chrome谷歌浏览器导致的密码被修改现象

    版本 68.0.3440.106(正式版本) (32 位)记住密码功能有个缺陷,会把自己的密码自动填写到别人的密码框中,假如这个时候点击保存密码,就会导致其他用户的密码被修改为登录用户的密码.   很 ...

  7. IE图片下载

    之前要用到图面下载功能,玩上找了好多,方法基本都是直接window.open(src),这样是直接在新打开的窗口中打开图片,并不是下载.考虑到IE的兼容性问题太难找了,好不容易找到一个能用的,所以保存 ...

  8. A - 移动的骑士

    A - 移动的骑士 Time Limit: 1000/1000MS (C++/Others) Memory Limit: 65536/65536KB (C++/Others) Problem Desc ...

  9. CentOS7中rpm,yum软件安装命令

    RPM包常用安装位置说明 /etc/                   配置文件安装目录 /usr/bin/               可执行的命令安装目录 /usr/lib/           ...

  10. IE浏览器报Promise未定义的错误

    背景: 一个vue-cli构建的vue项目,一个使用angular的项目,两个项目在其他浏览器一切正常,但是ie中会报Promise未定义的错误 解决办法: vue的项目: 1.  npm insta ...