leetcode

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

1845.cpp (367B)


      1 class SeatManager {
      2     priority_queue<int, vector<int>, greater<int>> pq;
      3     int used;
      4 
      5   public:
      6     SeatManager(int n) : used(0) {}
      7 
      8     int reserve() {
      9         if (!pq.empty()) {
     10             int seat = pq.top();
     11             pq.pop();
     12             return seat;
     13         }
     14         return ++used;
     15     }
     16 
     17     void unreserve(int seatNumber) { pq.push(seatNumber); }
     18 };