class MinStack {
public:
MinStack()
{
coll.resize(2);
}
void push(int x) {
if(index == coll.size()-1)
coll.resize(2*coll.size());
coll[++index]=x;
if(x<min)
{
min=x;
flag=index;
}
} void pop() {
index--; } int top() {
return coll[index];
} int getMin() {
if(index <flag&& index!=-1)
{
min=coll[0];
for(int i=1;i<=index;i++)
if(coll[i]<min)
{
min=coll[i];
flag=i;
}
} return min;
}
private:
vector<int> coll;
int index=-1;
int min=INT_MAX,flag;
};

  

LeetCode() Min Stack 不知道哪里不对,留待。的更多相关文章

  1. leetCode Min Stack解决共享

    原标题:https://oj.leetcode.com/problems/min-stack/ Design a stack that supports push, pop, top, and ret ...

  2. LeetCode: Min Stack 解题报告

    Min Stack My Submissions Question Solution Design a stack that supports push, pop, top, and retrievi ...

  3. [LeetCode] Min Stack 最小栈

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

  4. [LeetCode] Min Stack

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

  5. LeetCode——Min Stack

    Description: Design a stack that supports push, pop, top, and retrieving the minimum element in cons ...

  6. [leetcode] Min Stack @ Python

    原题地址:https://oj.leetcode.com/problems/min-stack/ 解题思路:开辟两个栈,一个栈是普通的栈,一个栈用来维护最小值的队列. 代码: class MinSta ...

  7. [LeetCode] Min Stack 栈

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

  8. LeetCode Min Stack 最小值栈

    题意:实现栈的四个基本功能.要求:在get最小元素值时,复杂度O(1). 思路:链表直接实现.最快竟然还要61ms,醉了. class MinStack { public: MinStack(){ h ...

  9. Min Stack [LeetCode 155]

    1- 问题描述 Design a stack that supports push, pop, top, and retrieving the minimum element in constant ...

随机推荐

  1. [Mysql] mysql临时表corrupt

    问题描述 机房临时硬件问题, 机器掉电. 恢复后, 重启mysql进程, 结果出现core dump. 而且一直循环, 无法终止, 只能kill掉. backtrace如下. # service my ...

  2. .ipynb文件 与ipython notebook

    没有安装ipython notebook 后看见.ipynb文件直接手足无措了 一.安装ipython notebook 使用命令 pip ipython [all] 为所有用户安装 ipython ...

  3. oracle的存储过程和函数(PL/SQL)

    czmmiao 存储过程概述 存储过程是子程序的一种类型,能够完成一些任务,作为schema对象存储于数据库.是一个有名字的PL/SQL代码块,支持接收或不接受参数,同时也支持参数输出.一个存储过程通 ...

  4. MultiDex到底有多坑

    google为什么要引入MultiDex? dex指令是用16位寄存器来保存dex中的方法数,所以限制了在apk 中最大的方法数为65535,当超过这个最大值在编译的时候会报 方法数超标的错误. 如何 ...

  5. 004_kafka_安装运行

    1.下载和安装 目前kafka的稳定版本为0.10.0.0 下载地址:http://kafka.apache.org/downloads.html 下载后解压缩安装包到系统即可完成安装 > ta ...

  6. Druid.io索引过程分析——时间窗,列存储,LSM树,充分利用内存,concise压缩

    Druid底层不保存原始数据,而是借鉴了Apache Lucene.Apache Solr以及ElasticSearch等检索引擎的基本做法,对数据按列建立索引,最终转化为Segment,用于存储.查 ...

  7. 【源码】c#编写的安卓客户端与Windows服务器程序进行网络通信

    NetworkComms网络通信框架序言 用c#开发安卓程序 (xamarin.android)系列之三 源码(包含客户端与服务器端所有工程文件)    数据库文件 为了方便您测试,我临时搭建了一个服 ...

  8. 使用urllib编写python爬虫

    新版python中,urllib和urllib2合并了,统一为urllib (1)简单爬取网页 import urllib content = urllib.request.urlopen(req). ...

  9. Struts2+Hibernate+Spring 整合示例[转]

    原文 http://blog.csdn.net/tkd03072010/article/details/7468769 Spring整合Struts2.Hibernate原理概述: 从用户角度来看,用 ...

  10. [转载]四大Java EE容器

    转载自: https://my.oschina.net/diedai/blog/271367 现在流行的Java EE容器有很多:Tomcat.JBoss.Resin.Glassfish等等.下面对这 ...