题干解读:停车场的停车规则类似于栈,只有靠经出口(栈顶)的车全部出去后,靠后的车辆才能出去.
要处理4种信息:
1.将停车的车辆的编号记录下来.
2.出去一辆车,删除他的编号信息。
3.输出最靠近出口的车辆的编号信息.
4.输出最小的车辆编号
思路:按照题干要求依次使用stack中的函数来解决即可.
class Solution {
public:
stack<int> s;
void push(int value) {
s.push(value);
}
void pop() {
s.pop();
}
int top() {
return s.top();
}
int min() {
stack<int> t =s;
int min =t.top();
t.pop();
while(!t.empty()){
if(t.top()<min){
min = t.top();
}
t.pop();
}
return min;
}
};

京公网安备 11010502036488号