LeetCode 3 :Min Stack
今天做了一道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的更多相关文章
- leetcode 155. Min Stack --------- java
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- Java [Leetcode 155]Min Stack
题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...
- 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 ...
- LeetCode 155 Min Stack(最小栈)
翻译 设计支持push.pop.top和在常量时间内检索最小元素的栈. push(x) -- 推送元素X进栈 pop() -- 移除栈顶元素 top() -- 得到栈顶元素 getMin() -- 检 ...
- [LeetCode] 0155. Min Stack 最小栈 & C++Runtime加速
题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. ...
- 【LeetCode】Min Stack 解题报告
[题目] Design a stack that supports push, pop, top, and retrieving the minimum element in constant tim ...
- 【leetcode】Min Stack -- python版
题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...
- Java for LeetCode 155 Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- LeetCode之Min Stack 实现最小栈
LeetCode相关的网上资源比较多,看到题目一定要自己做一遍,然后去学习参考其他的解法. 链接: https://oj.leetcode.com/problems/min-stack/ 题目描述: ...
- LeetCode之Min Stack
1.原文问题描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constan ...
随机推荐
- 国际电话区号SQL
CREATE TABLE `phone_prefix` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `country` varchar(30) N ...
- 在测试时用到的一些mysql的小技巧(持续更新)
经常使用的快捷键: 1.ctrl+q 打开查询窗口 2.ctrl+/ 注释sql语句 3.ctrl+shift +/ 解除注释 4.ctrl+r 运行查询窗口的sql语句 5.ctrl+shift+r ...
- CentOS环境配置Hadoop(一)
配置Linux开发环境(hadoop-2.6.4) 一.准备工具 VMware-workstation-10.0.1注册机 CentOS-6.5-x86_64-bin-DVD1 jdk-7u79-li ...
- C语言关于“输入包含多行数据,请处理到文件结束”的问题
今天,笔者在做本校ACM校赛网络赛的时候,遇到输入格式中有这样的要求:输入包含多行数据,请处理到文件结束.题目的逻辑很简单,主要功能代码很容易实现,但是题目中没有“明确”指出控制台中输入数据以什么方式 ...
- 时间动态协同过滤(TimeSVD++)
原作者 原论文地址 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.379.1951&rep=rep1&type=pd ...
- Python 学习笔记之—— PIL 库
PIL,全称 Python Imaging Library,是 Python 平台一个功能非常强大而且简单易用的图像处理库.但是,由于 PIL 仅支持到Python 2.7,加上年久失修,于是一群志愿 ...
- hyperledger composer
hyperledger composer 网站搜集 https://hyperledger.github.io/composer/latest/introduction/introduction.ht ...
- MyBatis整体了解
背景资料 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBati ...
- 团队项目-第十次scrum 会议
时间:11.6 时长:20分钟 地点:主235教室走廊 工作情况 团队成员 已完成任务 待完成任务 解小锐 完成多种招聘方式的逻辑编写 陈鑫 实现游戏的存档功能 李金奇 添加多种招聘方式等功能 王辰昱 ...
- PM所该学习的
最近第二阶段实在大家都是大一大二,面临的考试很多也很难,很多时候就开始松懈了下来.可是做事情就是需要效率和时间,慢慢地,也开始懈怠了下来. 作为pm,首先自己必须比组员先了解云笔记的各种进程,做好沟 ...