今天做了一道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. spring boot 过滤器实现接收 压缩数据 并解压

    1.新加类GzipRequestWrapper 继承HttpServletRequestWrapper类 public class GzipRequestWrapper extends HttpSer ...

  2. 配置SSH无密钥登陆(三)

    配置SSH无密钥登陆 (1).关闭防火墙 对每个虚拟机进行如下操作:   su    chkconfig  iptables  off 执行之后重启虚拟机:reboot (2).关闭之后,在maste ...

  3. 输出不重复的质因数(C++)

    [问题描述] 从键盘上输入一个大于 1 的正整数,输出它所有不等的质因数.(什么是质因数?既是质数,又是因数) [代码展示] # include<iostream>using namesp ...

  4. [Linux] 服务器镜像定时备份解决方案 crontab+rsync+flock

    两台服务器定时同步文件解决方案: 环境: 主机:192.168.1.1 镜像机:192.168.1.2 需要将主机内容备份至镜像机(假设用户都为root) 备份内容为 /export 目录下所有内容至 ...

  5. Eureka搭建

    Eureka搭建 一.Eureka基本框架搭建 pom.xml文件配置:主要是引入Eureka所依赖的jar包 <?xml version="1.0" encoding=&q ...

  6. HTTP 知新

    REST 先从 REST 的角度来看看 HTTP 协议规范, URL:需要操作的对象,也就是资源 HTTP method:我要对该对象做什么(POST 增.DELETE 删.GET 查.PUT 和 P ...

  7. 线段树——hdu1754I Hate It

    一.题目回顾 题目链接:I Hate It Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感.不管你喜不喜欢 ...

  8. Name node is in safe mode.

    刚才启动hadoop,然后执行rm -r命令,出现这个问题,标记为红色的部分意思是namenode是安全节点, [master@hadoop file]$ hadoop fs -rm -r  /inp ...

  9. SVN分支/主干Merge操作小记

    一.前言 说来惭愧,鄙人从事开发多年,使用svn已经好几个年头了,但是却仅限于update.commit.compare之类的操作,最近想到github上学习别人写的NIO源码,顺便去熟悉git的使用 ...

  10. web颜色转换为delphi

    今天在写写一个日志浏览和报警功能时,要求用多种颜色去显示不同的信息,客户给出的颜色是web的 rgb颜色,就是用6位16进制数去表示的颜色,直接把他赋值给Delphi的TColor变量,发现显示的颜色 ...