1845. Seat Reservation Manager

양성준·2025년 5월 12일

코딩테스트

목록 보기
51/102

문제

https://leetcode.com/problems/seat-reservation-manager/description/

풀이

class SeatManager {
    PriorityQueue<Integer> seat = new PriorityQueue<>();
    public SeatManager(int n) {
        for(int i = 1; i <= n; i++) {
            seat.add(i);
        }
    }
    
    public int reserve() {
        return seat.poll();
    }
    
    public void unreserve(int seatNumber) {
        seat.add(seatNumber);
    }
}
  • 가장 작은 수를 반복해서 꺼내기 -> min-heap 사용
profile
백엔드 개발자

0개의 댓글