包含min函数的栈java实现
2017-09-16 10:09
295 查看
定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数。
import java.util.Stack; public class Solution { Stack<Integer> stack=new Stack<Integer>(); Stack<Integer> stack2=new Stack<Integer>(); public void push(int node) { stack.push(node); } public void pop() { stack.pop(); } public int top() { return stack.peek(); } public int min() { int min=Integer.MAX_VALUE; while(stack.isEmpty()!=true){ int node=stack.pop(); if(node<min){ min=node; } stack2.push(node); } while(stack2.isEmpty()!=true){ stack.push(stack2.pop()); } return min; } }
相关文章推荐
- 《剑指offer》编程题java实现(二十):包含min函数的栈
- 剑指offer--面试题21:包含min函数的栈--Java实现
- 【老鸟学算法】包含 min函数的栈设计——java实现
- 包含min函数的栈(Java实现)
- 【剑指offer——JAVA实现】包含min函数的栈(含思路解答示意图)
- 包含min函数的栈 java实现
- 包含min函数的栈JAVA实现
- 【老鸟学算法】包含 min函数的栈设计——java实现
- 剑指Offer:面试题21——包含min函数的栈(java实现)
- 剑指offer 面试题21 包含min函数的栈 Java实现
- 设计包含min函数的栈 java实现
- 剑指Offer 面试题30:包含min函数的栈 Java代码实现
- 剑指Offer: (Java实现) 包含min函数的栈
- Java实现Flash请求的二进制流图片保存并返回XML信息包含图片访问地址
- 关于消息推送的补充,主要介绍服务端的实现,包含object c 版本 c 版本 java 版本 php 版本 (转)
- 经典面试题:设计包含min函数的栈,O(1)空间实现方法
- javaWeb_15-request实现页面包含
- java实现的二叉树(前序、中序、后序)递归和非递归遍历,包含层序遍历
- 题目1512:用两个栈实现队列 && 包含min函数的栈
- 利用Java针对MySql封装的jdbc框架类 JdbcUtils 完整实现(包含增删改查、JavaBean反射原理,附源码)