leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1845.cpp (367B)
0 class SeatManager { 1 priority_queue<int, vector<int>, greater<int>> pq; 2 int used; 3 4 public: 5 SeatManager(int n) : used(0) {} 6 7 int reserve() { 8 if (!pq.empty()) { 9 int seat = pq.top(); 10 pq.pop(); 11 return seat; 12 } 13 return ++used; 14 } 15 16 void unreserve(int seatNumber) { pq.push(seatNumber); } 17 };