标签:leetcode
https://oj.leetcode.com/problems/min-stack/
http://blog.csdn.net/linhuanmars/article/details/41008731
class MinStack { public void push(int x) { data.push(x); if (min.empty() || (x <= (int)min.peek())) { min.push(x); } } public void pop() { if (data.empty()) return; int toReturn = (int)data.pop(); if ((int)min.peek() == toReturn) { min.pop(); } } public int top() { return (int)data.peek(); } public int getMin() { return (int)min.peek(); } private Stack data = new Stack(); private Stack min = new Stack(); }
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1601273