2336. Smallest Number in Infinite Set - LeetCode
import heapq
class SmallestInfiniteSet:
def __init__(self):
self.i = 0
self.q = []
def popSmallest(self) -> int:
if self.q:
return heapq.heappop(self.q)
self.i += 1
return self.i
def addBack(self, num: int) -> None:
if num <= self.i and num not in self.q:
heapq.heappush(self.q, num)