标签:
public class Solution { Stack<Integer> data = new Stack<>(); Stack<Integer> min = new Stack<>(); Integer tmp = null; public void push(int node) { if(tmp!=null){ if(node<=tmp){ tmp = node; min.push(node); } data.push(node); }else{ min.push(node); tmp = node; data.push(node); } } public void pop() { int num = data.pop(); int num2 = min.pop(); if(num!=num2){ min.push(num2); } } public int top() { int num = data.pop(); data.push(num); return num; } public int min() { int num = min.pop(); min.push(num); return num; } }
标签:
原文地址:http://www.cnblogs.com/hesier/p/5585189.html