2336.js
/** ------------------------------------------------------------------------------
*
* 2023-04-25
* 2336. Smallest Number in Infinite Set
* https://leetcode.com/problems/smallest-number-in-infinite-set/
*
------------------------------------------------------------------------------ */
var SmallestInfiniteSet = function () {
this.array = new Array(1001).fill(true);
};
/**
* @return {number}
*/
SmallestInfiniteSet.prototype.popSmallest = function () {
for (let i = 1; i < this.array.length; i++) {
if (this.array[i]) {
this.array[i] = false;
return i;
}
}
return null;
};
/**
* @param {number} num
* @return {void}
*/
SmallestInfiniteSet.prototype.addBack = function (num) {
this.array[num] = true;
};
/**
* Your SmallestInfiniteSet object will be instantiated and called as such:
* var obj = new SmallestInfiniteSet()
* var param_1 = obj.popSmallest()
* obj.addBack(num)
*/