LoginSignup
0
0

Leetcode 1845. Seat Reservation Manager

Last updated at Posted at 2023-11-06

アプローチ

  • PriorityQueue
class SeatManager {

    PriorityQueue<Integer> pq;

    public SeatManager(int n) {
        this.pq = new PriorityQueue<>();
        for (int i = 1; i <= n; i++) {
            this.pq.add(i);
        }
    }

    public int reserve() {
        return pq.poll();
    }

    public void unreserve(int seatNumber) {
        pq.add(seatNumber);
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0