程式語言 - LeetCode - C++ - 2336. Smallest Number in Infinite Set



參考資訊:
https://algo.monster/liteproblems/2336

題目:


解答:

class SmallestInfiniteSet {
public:
    SmallestInfiniteSet() {
        for (int i = 1; i <= 1000; ++i) {
            q.insert(i);
        }
    }
    
    int popSmallest() {
        auto n = *q.begin();
        q.erase(q.begin());

        return n;
    }
    
    void addBack(int num) {
        q.insert(num);
    }

private:
    set<int> q;
};

/**
 * Your SmallestInfiniteSet object will be instantiated and called as such:
 * SmallestInfiniteSet* obj = new SmallestInfiniteSet();
 * int param_1 = obj->popSmallest();
 * obj->addBack(num);
 */