作者wu10200512 (廷廷)
看板Marginalman
標題Re: [閒聊] 每日LeetCode
時間Mon Jan 29 15:02:22 2024
寫完後發現去年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();
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.51.220 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1706511744.A.1AF.html
→ oin1104: 你好棒 01/29 15:03
推 DaibaNana: 你好厲害 01/29 15:03
推 JIWP: 大師 01/29 15:03
推 DJYOSHITAKA: 大濕... 01/29 15:27
→ pandix: 不是背起來 是你變強了 01/29 16:47