今天做了一道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. 剑指offer-反转链表15

    题目描述 输入一个链表,反转链表后,输出新链表的表头. class Solution: # 返回ListNode def ReverseList(self, pHead): # write code ...

  2. term "JavaScript"

    在Web浏览器上下文中理解的总称“JavaScript”包含几个非常不同的元素. 其中一个是核心语言(ECMAScript),另一个是Web API的集合,包括DOM(文档对象模型) JavaScri ...

  3. POJ 1463 Strategic game(二分图最大匹配)

    Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...

  4. 《鸟哥的Linux私房菜》读书笔记

    第五章  初次使用Linux man.info的使用 组合键:切换登录环境.Tab.Ctrl+c.Ctrl+d 正确关机的方法 开机过程的问题排解:文件系统错误.忘记root密码 第六章  文件权限& ...

  5. 并查集——poj1182(带权并查集高阶)

    题目链接:食物链 题解:点击 说一声:这题关系推导值得学习.

  6. [转]dwr3框架学习笔记--简介及原理简介

    1.DWR简介 DWR(直接web远程访问),DWR是一个Java库,使服务器上的Java和JavaScript的浏览器进行交互和相互调用尽可能简单. DWR 是一个可以允许你去创建 AJAX WEB ...

  7. C# 几种读取MAC地址的方法

    以下是收集的几种C#程序读取MAC地址的方法,示例中是读取所有网卡的MAC地址,如果仅需要读取其中一个,稍作修改即可. 1 通过IPConfig命令读取MAC地址 ///<summary> ...

  8. php laravel 框架搭建与运行

    目录 安装 composer 安装 laravel 运行 php hello world 一.安装 composer (mac) 下载 composer.phar 下载地址:https://getco ...

  9. jquery中ajax的使用(java)

    AJAX方式  js:界面 var prjContextPath='<%=request.getContextPath()%>'; $(document).ready(function() ...

  10. JVM内存区域配置

    堆内存:新域+旧域 设置堆内存初始化大小 java -Xms128m 设置堆内存初始化大小128MB 设置堆内存最大大小 java -Xmx256m 设置堆内存最大256MB 通常将堆内存的初始化大小 ...