-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (36 loc) · 1.08 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import heapq
class SmallestInfiniteSet:
def __init__(self):
self.mn = 1
self.pq = list()
self.exists = set()
def popSmallest(self) -> int:
if len(self.pq) == 0:
self.mn += 1
return self.mn - 1
v = heapq.heappop(self.pq)
print(v in self.exists)
self.exists.remove(v)
return v
def addBack(self, num: int) -> None:
if num >= self.mn or num in self.exists:
return
heapq.heappush(self.pq, num)
self.exists.add(num)
from sortedcontainers import SortedSet
class SmallestInfiniteSet:
def __init__(self):
self.mn = 1
self.st = SortedSet()
def popSmallest(self) -> int:
if len(self.st) == 0:
self.mn += 1
return self.mn - 1
return self.st.pop(0)
def addBack(self, num: int) -> None:
if num < self.mn:
self.st.add(num)
# Your SmallestInfiniteSet object will be instantiated and called as such:
# obj = SmallestInfiniteSet()
# param_1 = obj.popSmallest()
# obj.addBack(num)