[Random Coding]StackWithMin
来源:互联网 发布:美工板是什么意思 编辑:程序博客网 时间:2024/05/22 16:56
import java.util.Stack;public class StackWithMin {Stack<Integer> stack = new Stack<Integer>();Stack<Integer> min = new Stack<Integer>();public void push(Integer val){stack.push(val);if(min.isEmpty() || val <= min.peek())min.push(val);}public Integer pop(){if(!stack.isEmpty() && !min.isEmpty()){Integer val = stack.pop();if(val == min.peek())min.pop();return val;}return Integer.MIN_VALUE;}public Integer getMin(){if(!min.isEmpty())return min.peek();return Integer.MIN_VALUE;}}
0 0
- [Random Coding]StackWithMin
- stackWithMIn
- [Random Coding]QueueWithMin
- [Random Coding]Topological Sorting
- [Random Coding] Tree Iterator
- [Random Coding]Interval Related Questions
- [Random Coding] De/Serialization Binary Tree
- [Random Coding] De/Serialization of Binary Search Tree
- coding小记:np.random.randn与tf.random_normal
- Coding
- Coding
- coding
- coding
- coding
- coding
- Coding
- coding
- Coding
- ARToolKit
- Regular Expression Matching
- Decision Tree & Threaded Binary Tree & Information Entropy
- oracle net service
- [Random Coding]QueueWithMin
- [Random Coding]StackWithMin
- Quarterly Excel value expression
- struts2 struts.xml文件<constant>标签说明
- [Random Coding]Topological Sorting
- CMU软件选课体会
- 6天通吃树结构—— 第五天 Trie树
- 从Trie树(字典树)谈到后缀树
- Leetcode Word Break
- 倾城浅笑天涯远