class Solution { public: void push(int value) { st.push(value); } void pop() { st.pop(); } int top() { return st.top(); } int min() { int min_num=st.top(); while(!st.empty()){ int tmp = st.top(); if(tmp < min_num){ min_num = tmp; } tmp_st.push(tmp); pop(); } while(!tmp_st.empty()){ st.push(tmp_st.top()); tmp_st.pop(); } return min_num; } private: stack<int>st; stack<int>tmp_st; };
原文:https://www.cnblogs.com/grglym/p/8982552.html