155. Min Stack
来源:互联网 发布:seo入门博客 编辑:程序博客网 时间:2024/05/23 13:32
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.
st1保存正常数据,st2作为辅助栈保存递减子序列
class MinStack {public: void push(int x) { st1.push(x); if(st2.empty()) { st2.push(x); }else { if(st2.top() >= x) { st2.push(x); } } } void pop() { if(st1.top() <= st2.top()) { st2.pop(); } st1.pop(); } int top() { return st1.top(); } int getMin() { return st2.top(); }private: stack<int> st1; stack<int> st2;};
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
- 网上某位大神写的仿小米卸载动画eclipse版
- Revit二次开发(2):Hello World!
- OC_07_02 NSDate
- 【Educational Codeforces Round 3 B】【水题 基本容斥】The Best Gift n本书任选两个不能同一类型的方案数
- res/raw文件的存放和读取
- 155. Min Stack
- jQuery中this与$(this)的区别
- Revit二次开发(3):Revit动态模型更新(DMU: Dynamic Model Update)功能
- 快速搭建struts2+srping3+hibernate4框架
- ALV在保存带有小数的字段时候,在可编辑状态会自动少数
- SHU1919 Running Man,Bob(那罗延数)
- 元旦前随笔
- Understanding Convolutions
- Revit二次开发(4):对象存储的可扩展存储框架