155. Min Stack
来源:互联网 发布:雅思大作文 知乎 编辑:程序博客网 时间:2024/06/06 02:04
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
- push(x) -- Push element x onto stack.
- pop() -- Removes the element on top of the stack.
- top() -- Get the top element.
- getMin() -- Retrieve the minimum element in the stack.
class MinStack {public://用vector实现似乎比stack快 stack<int> s; stack<int> min; void push(int x) { if(s.empty()){ min.push(x); } else if(min.top()>=x)min.push(x); s.push(x); } void pop() { int temp=s.top(); s.pop(); if(temp==min.top())min.pop(); } int top() { return s.top(); } int getMin() { return min.top(); }};
0 0
- Stack-----155. Min Stack
- LeetCode 155. Min Stack
- 【LeetCode】155.Min Stack
- LeetCode 155.Min Stack
- [leetcode] 155.Min Stack
- [leetcode] 155.Min Stack
- 155. Min Stack
- 155. Min Stack
- Leetcode 155. Min Stack
- 155. Min Stack
- 155. Min Stack LeetCode
- 155. Min Stack
- [LeetCode]155. Min Stack
- 155. Min Stack
- 155. Min Stack
- 155. Min Stack
- LeetCode *** 155. Min Stack
- 【leetcode】155. Min Stack
- 欢迎使用CSDN-markdown编辑器
- javax.el.PropertyNotFoundException: Property 'emailaddress' not found on type ja
- Elasticsearch IK 同义词
- CSU-1336--Interesting Calculator(bfs)
- 线程和进程的区别和联系
- 155. Min Stack
- js常用事件总结及案例-onSubmit
- 编程小练习
- 使用Android Studio时你应该知道的一些配置
- 【android】:android实现打开网页和拨打电话
- SQL 语句一行拆成多行及多行合并成一行的方法
- Redmine使用手册
- Linux下使用iptables禁止指定IP地址的网络连接
- Qt布局管理: 堆栈窗体QStackedWidget类(纯代码实现)