Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 380 Bytes

1845. Seat Reservation Manager.md

File metadata and controls

21 lines (16 loc) · 380 Bytes

CODE for '1845. Seat Reservation Manager' ( Java )

class SeatManager {
  public SeatManager(int n) {}

  public int reserve() {
    if (minHeap.isEmpty())
      return ++num;
    return minHeap.poll();
  }

  public void unreserve(int seatNumber) {
    minHeap.offer(seatNumber);
  }

  private Queue<Integer> minHeap = new PriorityQueue<>();
  private int num = 0;
}