We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 08d5d21 commit bcc80bfCopy full SHA for bcc80bf
Medium/Seat Reservation Manager.java
@@ -1,23 +1,21 @@
1
class SeatManager {
2
3
- PriorityQueue<Integer> pq;
4
- int count;
+ private PriorityQueue<Integer> seats;
5
6
- public SeatManager(int n) {
7
- pq = new PriorityQueue<>();
8
- count = 1;
9
- }
10
-
11
- public int reserve() {
12
- if (pq.size() == 0) {
13
- return count++;
+ public SeatManager(int n) {
+ this.seats = new PriorityQueue<>();
+ for (int i = 1; i <= n; i++) {
+ this.seats.add(i);
+ }
+
+ public int reserve() {
+ return this.seats.poll();
14
15
16
+ public void unreserve(int seatNumber) {
17
+ this.seats.add(seatNumber);
18
}
- return pq.remove();
- public void unreserve(int seatNumber) {
19
- pq.add(seatNumber);
20
21
22
23
/**
0 commit comments