Skip to content

Commit

Permalink
Time: 133 ms (16.36%), Space: 113.7 MB (12.43%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
saikatkar committed Jan 2, 2022
1 parent 8833b9b commit c0828d6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions seat-reservation-manager/seat-reservation-manager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class SeatManager {
Queue<Integer> minHeap = null;
int number = 0;
public SeatManager(int n) {
minHeap = new PriorityQueue<>();
minHeap.add(1);
}

public int reserve() {
int reserve = minHeap.poll();
if (minHeap.isEmpty()) {
minHeap.add(reserve+1);
}
return reserve;
}

public void unreserve(int seatNumber) {
minHeap.add(seatNumber);
}
}

/**
* Your SeatManager object will be instantiated and called as such:
* SeatManager obj = new SeatManager(n);
* int param_1 = obj.reserve();
* obj.unreserve(seatNumber);
*/

0 comments on commit c0828d6

Please sign in to comment.