题目描述
没有使用c++的Stack,傻傻的自己写了个顺序栈。。。
样例
class MinStack {
public:
/** initialize your data structure here. */
struct Stack{
int nums[10001];
int top = 0;
}stack;
MinStack() {
}
void push(int x) {
stack.nums[stack.top] = x;
stack.top ++;
//cout << stack.top << endl;
}
void pop() {
//stack.nums[stack.top] = 0;
stack.top--;
}
int top() {
return stack.nums[stack.top - 1];
}
int getMin() {
int min = 1e5;
for(int i = 0; i < stack.top; i++)
{
if(stack.nums[i] < min)
min = stack.nums[i];
}
return min;
}
};