# [Solution] Smallest Number in Infinite Set solution leetcode

Smallest Number in Infinite Set solution leetcode – You have a set which contains all positive integers `[1, 2, 3, 4, 5, ...]`.

## [Solution] Smallest Number in Infinite Set solution leetcode

Implement the `SmallestInfiniteSet` class:

• `SmallestInfiniteSet()` Initializes the SmallestInfiniteSet object to contain all positive integers.
• `int popSmallest()` Removes and returns the smallest integer contained in the infinite set.
• `void addBack(int num)` Adds a positive integer `num` back into the infinite set, if it is not already in the infinite set.

## [Solution] Smallest Number in Infinite Set solution leetcode

```Input
[[], [2], [], [], [], [1], [], [], []]
Output
[null, null, 1, 2, 3, null, 1, 4, 5]

Explanation
SmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet();
smallestInfiniteSet.popSmallest(); // return 1, since 1 is the smallest number, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 2, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 3, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 1, since 1 was added back to the set and
// is the smallest number, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 4, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 5, and remove it from the set.
```

## [Solution] Smallest Number in Infinite Set solution leetcode

• `1 <= num <= 1000`
• At most `1000` calls will be made in total to `popSmallest` and `addBack`.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://codefreshers.com/smallest-number-in-infinite-set-solution-leetcode/", "fetch_time": 1660241454000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2022-33/segments/1659882571483.70/warc/CC-MAIN-20220811164257-20220811194257-00511.warc.gz", "warc_record_offset": 207244070, "warc_record_length": 11890, "token_count": 451, "char_count": 1585, "score": 3.53125, "int_score": 4, "crawl": "CC-MAIN-2022-33", "snapshot_type": "latest", "language": "en", "language_score": 0.4195942282676697, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00011-of-00064.parquet"}