File tree
Expand file treeCollapse file tree1 file changed
+14
-16
lines changed Expand file treeCollapse file tree1 file changed
+14
-16
lines changed Original file line number | Diff line number | Diff line change |
---|
|
1 | 1 | class SeatManager {
|
2 | 2 |
|
3 |
| -PriorityQueue<Integer> pq; |
4 |
| -int count; |
| 3 | +private PriorityQueue<Integer> seats; |
5 | 4 |
|
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); |
14 | 18 | }
|
15 |
| -return pq.remove(); |
16 |
| -} |
17 |
| - |
18 |
| -public void unreserve(int seatNumber) { |
19 |
| -pq.add(seatNumber); |
20 |
| -} |
21 | 19 | }
|
22 | 20 |
|
23 | 21 | /**
|
|
You can’t perform that action at this time.
0 commit comments