leetcode-min stack
来源:互联网 发布:中国税务网络大学登录 编辑:程序博客网 时间:2024/06/06 15:03
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 { private LinkedList<Integer> stack=new LinkedList<Integer>(); int min=Integer.MAX_VALUE; // if it's min the initial value should be max public void push(int x) { stack.add(x); if(x<min)min=x; } public void pop() { Integer cur=stack.removeLast(); if(cur==min){ min=Integer.MAX_VALUE; // this should be max for(Integer a:stack){ if(a<min)min=a; } } } public int top() { return stack.get(stack.size()-1); } public int getMin() { return min; }}
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
- Ajax 调Handler页面,以及WebService
- 关于 Wave 文件的基础知识与文件格式
- NSObject不常用方法汇总
- 关于- tableView:cellForRowAtIndexPath:里cell的frame问题
- poj-2635(同余模运算)
- leetcode-min stack
- 为什么在定义hashcode时要使用31这个数?
- PHP字符串检测
- 内网与外网间通信
- 以前用phonegap开发商城系统,现在陆续开放出来,供大家学习
- 计算机视觉相关网站整理
- Java实现超大数字相加的算法
- python shutil os os.path模块 open总结
- gcc 编译warning 去除