leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0225.cpp (369B)


      1 
      2 class MyStack {
      3     queue<int> q;
      4 
      5   public:
      6     void push(int x) {
      7         q.push(x);
      8         for (int i = 0; i < q.size() - 1; i++) {
      9             q.push(q.front());
     10             q.pop();
     11         }
     12     }
     13 
     14     int pop() {
     15         int x = q.front();
     16         q.pop();
     17         return x;
     18     }
     19 
     20     int top() { return q.front(); }
     21     bool empty() { return q.empty(); }
     22 };