2336. 无限集中的最小数字
题目链接:2336. 无限集中的最小数字
代码如下:
class SmallestInfiniteSet
{
public:
SmallestInfiniteSet() {}
int popSmallest()
{
int res;
if(s.empty())
{
res=maxNum++;
return res;
}
res=*s.begin();
s.erase(s.begin());
return res;
}
void addBack(int num)
{
if(num<maxNum){s.insert(num);}
}
private:
set<int> s;
int maxNum=1;
};
/**
* Your SmallestInfiniteSet object will be instantiated and called as such:
* SmallestInfiniteSet* obj = new SmallestInfiniteSet();
* int param_1 = obj->popSmallest();
* obj->addBack(num);
*/