标签:
1 class Solution { 2 public: 3 4 stack<int> stack1,stack2; 5 6 void push(int value) { 7 stack1.push(value); 8 if(stack2.empty()) 9 stack2.push(value); 10 else if(value<=stack2.top()) 11 { 12 stack2.push(value); 13 } 14 } 15 16 void pop() { 17 if(stack1.top()==stack2.top()) 18 stack2.pop(); 19 stack1.pop(); 20 21 } 22 23 int top() { 24 return stack1.top(); 25 } 26 27 int min() { 28 return stack2.top(); 29 } 30 31 };
标签:
原文地址:http://www.cnblogs.com/SeekHit/p/5774115.html