#include <stack>
using namespace std;
class Solution {
public:
void push(int value) {
s.push(value);
}
void pop() {
if (!s.empty())
{s.pop();}
}
int top() {
return s.top();
}
int min() {
stack<int> temp;
int max = ~(1 << (sizeof(int) * 8 - 1));
while (!s.empty()) {
temp.push(top());
if (top() < max) {
max = top();
}
pop();
}
while (!temp.empty())
{
s.push(temp.top());
temp.pop();
}
return max;
}
private:
stack<int> s;
};
包含min函数的栈
最新推荐文章于 2021-11-30 11:47:27 发布