LeetCode 1845. 座位预约管理系统(滑动窗口)
原题链接
中等
作者:
autumn_0
,
2024-09-30 13:06:50
,
所有人可见
,
阅读 7
class SeatManager {
PriorityQueue<Integer> pq = new PriorityQueue<>();
public SeatManager(int n) {
for(int i = 1; i <= n; i ++ )
pq.offer(i);
}
public int reserve() {
return pq.poll();
}
public void unreserve(int seatNumber) {
pq.offer(seatNumber);
}
}
/**
* Your SeatManager object will be instantiated and called as such:
* SeatManager obj = new SeatManager(n);
* int param_1 = obj.reserve();
* obj.unreserve(seatNumber);
*/