leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0225.cpp (369B)
0 1 class MyStack { 2 queue<int> q; 3 4 public: 5 void push(int x) { 6 q.push(x); 7 for (int i = 0; i < q.size() - 1; i++) { 8 q.push(q.front()); 9 q.pop(); 10 } 11 } 12 13 int pop() { 14 int x = q.front(); 15 q.pop(); 16 return x; 17 } 18 19 int top() { return q.front(); } 20 bool empty() { return q.empty(); } 21 };