Skip to content

Commit bcc80bf

Browse files
authored
Update Seat Reservation Manager.java
1 parent 08d5d21 commit bcc80bf

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Medium/Seat Reservation Manager.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
class SeatManager {
22

3-
PriorityQueue<Integer> pq;
4-
int count;
3+
private PriorityQueue<Integer> seats;
54

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++;
5+
public SeatManager(int n) {
6+
this.seats = new PriorityQueue<>();
7+
for (int i = 1; i <= n; i++) {
8+
this.seats.add(i);
9+
}
10+
}
11+
12+
public int reserve() {
13+
return this.seats.poll();
14+
}
15+
16+
public void unreserve(int seatNumber) {
17+
this.seats.add(seatNumber);
1418
}
15-
return pq.remove();
16-
}
17-
18-
public void unreserve(int seatNumber) {
19-
pq.add(seatNumber);
20-
}
2119
}
2220

2321
/**

0 commit comments

Comments
 (0)