since there's only limit 1000 call counts, we can assume the potential operating numbers are below 1000.
create heapq that contains 1000 integer in order
init the heap
popSmallest => heappop
addBack => if not in list, add the num into heapq
class SmallestInfiniteSet:
heap = []
def __init__(self):
self.heap = [i for i in range(1, 1001)]
heapify(self.heap)
def popSmallest(self) -> int:
return heappop(self.heap)
def addBack(self, num: int) -> None:
if num not in self.heap:
heappush(self.heap, num)
# Your SmallestInfiniteSet object will be instantiated and called as such:
# obj = SmallestInfiniteSet()
# param_1 = obj.popSmallest()
# obj.addBack(num)
since there's only limit 1000 call counts, we can assume the potential operating numbers are below 1000.