We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a048362 commit aa2722fCopy full SHA for aa2722f
Python/seat-reservation-manager.py
@@ -0,0 +1,29 @@
1
+# Time: ctor: O(n)
2
+# reserve: O(logn)
3
+# unreserve: O(logn)
4
+# Space: O(n)
5
+
6
+import heapq
7
8
9
+class SeatManager(object):
10
11
+ def __init__(self, n):
12
+ """
13
+ :type n: int
14
15
+ self.__min_heap = range(1, n+1)
16
+ # heapq.heapify(self.__min_heap) # no need for sorted list
17
18
+ def reserve(self):
19
20
+ :rtype: int
21
22
+ return heapq.heappop(self.__min_heap)
23
24
+ def unreserve(self, seatNumber):
25
26
+ :type seatNumber: int
27
+ :rtype: None
28
29
+ heapq.heappush(self.__min_heap, seatNumber)
0 commit comments