写完后发现去年5月写过了
那时候应该是抄某个答案的
结果我一年后再写一遍 一模一样
答案直接背起来 笑死
class MyQueue {
public:
stack<int> in;
stack<int> out;
MyQueue() {
}
void push(int x) {
in.push(x);
}
int pop() {
if(out.empty()){
while(!in.empty()){
out.push(in.top());
in.pop();
}
}
int top = out.top();
out.pop();
return top;
}
int peek() {
if(out.empty()){
while(!in.empty()){
out.push(in.top());
in.pop();
}
}
int top = out.top();
return top;
}
bool empty() {
return in.empty() && out.empty();
}
};