package leetcode;

/**
 * https://leetcode.com/problems/seat-reservation-manager/
 */
public class Problem1845 {
    private static class SeatManager {
        public SeatManager(int n) {
            // TODO
        }

        public int reserve() {
            // TODO
            return 0;
        }

        public void unreserve(int seatNumber) {
            // TODO
        }
    }

    public static void main(String[] args) {
        SeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.
        System.out.println(seatManager.reserve()); // All seats are available, so return the lowest numbered seat, which is 1.
        System.out.println(seatManager.reserve()); // The available seats are [2,3,4,5], so return the lowest of them, which is 2.
        seatManager.unreserve(2); // Unreserve seat 2, so now the available seats are [2,3,4,5].
        System.out.println(seatManager.reserve()); // The available seats are [2,3,4,5], so return the lowest of them, which is 2.
        System.out.println(seatManager.reserve()); // The available seats are [3,4,5], so return the lowest of them, which is 3.
        System.out.println(seatManager.reserve()); // The available seats are [4,5], so return the lowest of them, which is 4.
        System.out.println(seatManager.reserve()); // The only available seat is seat 5, so return 5.
        seatManager.unreserve(5); // Unreserve seat 5, so now the available seats are [5].
    }
}

@@ -12,16 +12,43 @@
 tcode;%0A%0A
+import java.util.TreeSet;%0A%0A
 /**%0A * h
@@ -185,1311 +185,362 @@
    p
-ublic SeatManager(int n) %7B%0A            // TODO%0A        %7D%0A%0A        public int reserve() %7B%0A            // TODO%0A            return 0;%0A        %7D%0A%0A        public void unreserve(int seatNumber) %7B%0A            // TODO%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        SeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.%0A        System.out.println(seatManager.reserve()); // All seats are available, so return the lowest numbered seat, which is 1.%0A        System.out.println(seatManager.reserve()); // The available seats are %5B2,3,4,5%5D, so return the lowest of them, wh
+rivate final TreeSet%3CInteger%3E set = new TreeSet%3C%3E();%0A%0A        public SeatManager(int n) %7B%0A            for (int i = 1; i %3C= n; i++) %7B%0A                set.add(i);%0A            %7D%0A        %7D%0A%0A        publ
 ic
-h
  i
-s 2.%0A        seatManager.unreserve(2); // Unreserve seat 2, so now the available seats are %5B2,3,4,5%5D.%0A        System.out.println(seatManager.reserve()); // The available seats are %5B2,3,4,5%5D, so return the lowest of them, which is 2.%0A        System.out.println(seatManager.reserve()); // The available seats are %5B3,4,5%5D, so return the lowest of them, which is 3.%0A        System.out.println(seatManager.reserve()); // The available seats are %5B4,5%5D, so return the lowest of them, which is 4.%0A        System.out.println(seatManager.reserve()); // The only available seat is seat 5, so return 5.%0A        seatManager.unreserve(5); // Unreserve seat 5, so now the available seats are %5B5%5D.
+nt reserve() %7B%0A            return set.pollFirst();%0A        %7D%0A%0A        public void unreserve(int seatNumber) %7B%0A            set.add(seatNumber);%0A        %7D
 %0A   

Solve problem 1845