LeetCode() Min Stack 不知道哪里不对,留待。
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 不知道哪里不对,留待。的更多相关文章
- leetCode Min Stack解决共享
原标题:https://oj.leetcode.com/problems/min-stack/ Design a stack that supports push, pop, top, and ret ...
- LeetCode: Min Stack 解题报告
Min Stack My Submissions Question Solution Design a stack that supports push, pop, top, and retrievi ...
- [LeetCode] Min Stack 最小栈
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- [LeetCode] Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- LeetCode——Min Stack
Description: Design a stack that supports push, pop, top, and retrieving the minimum element in cons ...
- [leetcode] Min Stack @ Python
原题地址:https://oj.leetcode.com/problems/min-stack/ 解题思路:开辟两个栈,一个栈是普通的栈,一个栈用来维护最小值的队列. 代码: class MinSta ...
- [LeetCode] Min Stack 栈
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- LeetCode Min Stack 最小值栈
题意:实现栈的四个基本功能.要求:在get最小元素值时,复杂度O(1). 思路:链表直接实现.最快竟然还要61ms,醉了. class MinStack { public: MinStack(){ h ...
- Min Stack [LeetCode 155]
1- 问题描述 Design a stack that supports push, pop, top, and retrieving the minimum element in constant ...
随机推荐
- Reverse a singly linked list
Reverse a singly linked list. /** * Definition for singly-linked list. * struct ListNode { * int val ...
- composer安装fxp插件时候提示内存不足且没有交换空间的解决办法
The following exception is caused by a lack of memory and not having swap Check https://getcomposer. ...
- 【Todo】【转载】深入理解Java内存模型
提纲挈领地说一下Java内存模型: 什么是Java内存模型 Java内存模型定义了一种多线程访问Java内存的规范.Java内存模型要完整讲不是这里几句话能说清楚的,我简单总结一下Java内存模型的几 ...
- bridge
1 意图:将抽象部分与实现部分分离,使得它们都可以独立地变化 2 别名:Handle/Body 3 动机:客户在创建窗口时应该不涉及到具体实现部分.仅仅是窗口的实现部分依赖于应用运行的平台. 客户代码 ...
- SQL Server如何删除多余tempDB文件
某时,创建了多个tempDB文件,已经超过了服务器核心数,现象删除tempDB文件,使其保持与CPU核心数相同.但是在删除的时候,发现无法删除,报出错误:无法删除文件“tempdev3”,因为它不能为 ...
- Loom工具使用分享
Unity多线程(Thread)和主线程(MainThread)交互使用类——Loom工具分享 时间 2014-03-09 11:04:04 ITeye-博客 原文 http://dsqiu.it ...
- Retrofit 2.0使用(2)如何使用@Body的形式发送Post
在使用Retrofit的时候如果只是有几个参数我们可以用@Querry的形式,然后需要使用','隔开 但是在需要@Querry的参数多了之后,如果再用上面的方式就会造成参数写了一大堆的麻烦事 所以Re ...
- Github上传代码菜鸟超详细教程【转】
最近需要将课设代码上传到Github上,之前只是用来fork别人的代码. 这篇文章写得是windows下的使用方法. 第一步:创建Github新账户 第二步:新建仓库 第三部:填写名称,简介(可选), ...
- SPSS数据分析—非参数检验
统计学的假设检验可以分为参数检验和非参数检验,参数检验都是根据一些假设条件推算而来,当这些假设条件无法满足的时候,参数检验的效能会大打折扣,甚至出现错误的结果,而非参数检验通常是没有假设条件的,因此应 ...
- 如何查看ipa包支持哪些cpu指令集
将ipa包下载到本地 cd 到其所在目录 unzip lipo -info Moon(app名)