2336. Smallest Number in Infinite Set
class SmallestInfiniteSet:
def __init__(self):
self.heap = []
self.popped = set()
for i in range(1, 1001):
heappush(self.heap, i)
def popSmallest(self) -> int:
smallest_num = heappop(self.heap)
self.popped.add(smallest_num)
return smallest_num
def addBack(self, num: int) -> None:
if num in self.popped:
heappush(self.heap, num)
self.popped.remove(num)