leetcode Min Stack
来源:互联网 发布:fs forse.js 编辑:程序博客网 时间:2024/05/21 10:11
原题链接:https://leetcode.com/problems/min-stack/
Description
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: void push(int x) { if (val.empty() || x <= val.top()) val.push(x); num.push(x); } void pop() { if (num.top() <= val.top()) val.pop(); num.pop(); } int top() { return num.top(); } int getMin() { return val.top(); }private: stack<int> num; stack<int> val;};
0 0
- LeetCode[stack]: Min Stack
- [leetcode][stack] Min Stack
- 【Leetcode】Min Stack
- Leetcode: Min Stack
- leetcode Min stack
- Min Stack -- LeetCode
- Leetcode: Min Stack
- 【LeetCode】Min Stack
- leetcode Min Stack
- leetcode--Min Stack
- [Leetcode]Min stack
- leetcode:Min Stack
- leetcode 之 Min Stack
- leetcode Min Stack
- LeetCode(155) Min Stack
- [LeetCode]Min Stack
- leetcode:Min Stack
- leetcode - Min Stack
- 大转盘游戏
- html返回上一页
- int 与String之间的转换
- 我就是想看一下博客多久能显示出来
- Java中函数参数的传递形式是值传递 还是引用传递
- leetcode Min Stack
- MySQL之----在java编程加强知识点
- SAP接口编程-RFC系列04 : 动态调用SAP函数
- 关于LinkedList的操作--重点
- wordCount的认识(java版)
- centos7 minimal connect: Network is unreachable
- 1191: [HNOI2006]超级英雄Hero
- 深入理解计算机系统中网络编程一节echo客户端服务器的源码编译和运行
- Android静态变量的生命周期