cppclass SmallestInfiniteSet {
public:
SmallestInfiniteSet() {}
int popSmallest() {
if (s.empty()) {
int ans = thres;
++thres;
return ans;
}
int ans = *s.begin();
s.erase(s.begin());
return ans;
}
void addBack(int num) {
if (num < thres) {
s.insert(num);
}
}
private:
int thres = 1;
set<int> s;
};
本文作者:yowayimono
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!