You have a set which contains all positive integers [1, 2, 3, 4, 5, ...].

Implement the SmallestInfiniteSet class:


	SmallestInfiniteSet() Initializes the SmallestInfiniteSet object to contain all positive integers.
	int popSmallest() Removes and returns the smallest integer contained in the infinite set.
	void addBack(int num) Adds a positive integer num back into the infinite set, if it is not already in the infinite set.


&nbsp;
Example 1:

Input
["SmallestInfiniteSet", "addBack", "popSmallest", "popSmallest", "popSmallest", "addBack", "popSmallest", "popSmallest", "popSmallest"]
[[], [2], [], [], [], [1], [], [], []]
Output
[null, null, 1, 2, 3, null, 1, 4, 5]

Explanation
SmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet();
smallestInfiniteSet.addBack(2);    // 2 is already in the set, so no change is made.
smallestInfiniteSet.popSmallest(); // return 1, since 1 is the smallest number, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 2, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 3, and remove it from the set.
smallestInfiniteSet.addBack(1);    // 1 is added back to the set.
smallestInfiniteSet.popSmallest(); // return 1, since 1 was added back to the set and
                                   // is the smallest number, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 4, and remove it from the set.
smallestInfiniteSet.popSmallest(); // return 5, and remove it from the set.


&nbsp;
Constraints:


	1 &lt;= num &lt;= 1000
	At most 1000 calls will be made in total to popSmallest and addBack.


class SmallestInfiniteSet:

    def __init__(self):
        self.index = 1
        self.heap = []

    def popSmallest(self) -> int:
        if self.heap:
            return heapq.heappop(self.heap)
        self.index += 1
        return self.index-1

    def addBack(self, num: int) -> None:
        if self.index > num and num not in self.heap:
            heapq.heappush(self.heap,num)
class SmallestInfiniteSet {
    private PriorityQueue<Integer> q;
    private int index;
    public SmallestInfiniteSet() {
        q = new PriorityQueue<Integer>();
        index = 1;
    }
    
    public int popSmallest() {
        if (q.size()>0){
            return q.poll();
        }
        return index++;
    }
    
    private boolean is_in_q(int num){
        for(int i : q){
            if (i == num){
                return true;
            }
        }
        return false;
    }
    
    public void addBack(int num) {
        if( num < index && !is_in_q(num)){
            q.add(num);
        }
    }
}
class SmallestInfiniteSet {
public:
    int cur;
    set<int> s;
    SmallestInfiniteSet() {
        cur=1;
    }

    int popSmallest() {
        if(s.size()){
            int res=*s.begin(); s.erase(res);
            return res;
        }else{
            cur+=1;
            return cur-1;
        }
    }

    void addBack(int num) {
        if(cur>num) s.insert(num);
    }
};
var SmallestInfiniteSet = function() {
    const s = new Set();
    this.s = s;
    for(let i = 1; i <= 1000; i++) s.add(i);
};

/**
 * @return {number}
 */
SmallestInfiniteSet.prototype.popSmallest = function() {
    const min = Math.min(...Array.from(this.s));
    this.s.delete(min);
    return min;
};

/**
 * @param {number} num
 * @return {void}
 */
SmallestInfiniteSet.prototype.addBack = function(num) {
    this.s.add(num);
};

/**
 * Your SmallestInfiniteSet object will be instantiated and called as such:
 * var obj = new SmallestInfiniteSet()
 * var param_1 = obj.popSmallest()
 * obj.addBack(num)
 */
Smallest Number in Infinite Set