精華區beta Marginalman 關於我們 聯絡資訊
232. Implement Queue using Stacks easy題 這好簡單 剛好開始的時候寫完 趕緊來看 class MyQueue { stack<int> in; stack<int> out; public: MyQueue() { } void push(int x) { in.push(x); } int pop() { if(out.empty()){ while(!in.empty()){ out.push(in.top()); in.pop(); } } int temp = out.top(); out.pop(); return temp; } int peek() { if(out.empty()){ while(!in.empty()){ out.push(in.top()); in.pop(); } } return out.top(); } bool empty() { if(in.empty()&&out.empty()) return true; return false; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.137.157.124 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1679216986.A.5A4.html
DDFox: 無情的刷題機器人 03/19 17:10
andyshuo: 問一下 你刷題complexity是implement到甚麼程度才收手 03/19 17:16