2413. Smallest Number in Infinite Set
My accepted Python solution to LeetCode problem 2413, Smallest Number in Infinite Set, running in 16ms.
- Difficulty: Medium
- Python
- Runtime 16ms
- Memory 17.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 16ms, memory 17.9MB, accepted 2025-12-29.
class SmallestInfiniteSet:
def __init__(self):
self.cur = 1
self.s = set()
def popSmallest(self) -> int:
if self.s:
res = min(self.s)
self.s.remove(res)
return res
self.cur += 1
return self.cur - 1
def addBack(self, num: int) -> None:
if num < self.cur:
self.s.add(num)