leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2336.cpp (357B)


      1 class SmallestInfiniteSet {
      2     int count = 1;
      3     set<int> st;
      4 
      5   public:
      6     int popSmallest() {
      7         if (!st.empty()) {
      8             int elem = *st.begin();
      9             st.erase(st.begin());
     10             return elem;
     11         }
     12         return count++;
     13     }
     14 
     15     void addBack(int num) {
     16         if (num >= count) return;
     17         st.insert(num);
     18     }
     19 };