标签:
1 import java.util.Stack; 2 3 public class Solution { 4 5 Stack<Integer> s1 = new Stack<Integer>() ; 6 Stack<Integer> s2 = new Stack<Integer>() ; 7 public void push(int node) { 8 s1.push(node) ; 9 if(s2.size()==0||node<s2.peek()){ 10 s2.push( node) ; 11 } 12 else 13 s2.push( s2.peek()); 14 } 15 public int top() { 16 return s1.peek() ; 17 } 18 public void pop() { 19 if(s1.size()>0&&s2.size()>0){ 20 s1.pop() ; 21 s2.pop() ; 22 } 23 } 24 25 public int min() { 26 if(s1.size()>0&&s2.size()>0){ 27 return s2.peek() ; 28 } 29 return Integer.MAX_VALUE ; 30 } 31 }
标签:
原文地址:http://www.cnblogs.com/huntertoung/p/4779957.html