Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit588a3e1

Browse files
authored
Added Seat Reservation Manager.java
1 parent2fdbcab commit588a3e1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎Medium/Seat Reservation Manager.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
classSeatManager {
2+
3+
PriorityQueue<Integer>pq;
4+
intcount;
5+
6+
publicSeatManager(intn) {
7+
pq =newPriorityQueue<>();
8+
count =1;
9+
}
10+
11+
publicintreserve() {
12+
if (pq.size() ==0) {
13+
returncount++;
14+
}
15+
returnpq.remove();
16+
}
17+
18+
publicvoidunreserve(intseatNumber) {
19+
pq.add(seatNumber);
20+
}
21+
}
22+
23+
/**
24+
* Your SeatManager object will be instantiated and called as such:
25+
* SeatManager obj = new SeatManager(n);
26+
* int param_1 = obj.reserve();
27+
* obj.unreserve(seatNumber);
28+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp