leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2336.cpp (357B)
0 class SmallestInfiniteSet {
1 int count = 1;
2 set<int> st;
4 public:
5 int popSmallest() {
6 if (!st.empty()) {
7 int elem = *st.begin();
8 st.erase(st.begin());
9 return elem;
10 }
11 return count++;
12 }
14 void addBack(int num) {
15 if (num >= count) return;
16 st.insert(num);
17 }
18 };