# Leetcode 1286 Iterator for Combination

combination，看到这个词，就觉得这道题是位操作的题，想到位操作，就头疼，不擅长啊。

class CombinationIterator {
public:
CombinationIterator(string characters, int combinationLength) {
const int n = characters.size();
function<void(int, string)> helper = [&] (const int idx, string cur) {
if (cur.size() == combinationLength) {
dq_.push_back(cur);
return;
}
for (int i = idx; i < n; ++i)
helper(i + 1, cur + characters[i]);
};
helper(0, "");
}

// It's guaranteed that all calls of the function next are valid.
string next() {
string res = dq_.front();
dq_.pop_front();
return res;
}

bool hasNext() {
return !dq_.empty();
}
deque<string> dq_;
};


class CombinationIterator {
public:
CombinationIterator(string characters, int combinationLength):
chars_ (characters.rbegin(), characters.rend()) {
n_ = combinationLength;
mask_ = (1 << characters.size()) - 1;
}

string next() {
hasNext();
string res;
for (int i = chars_.size() - 1; i >= 0; --i)
if ((mask_ >> i) & 1)
res.push_back(chars_[i]);
return res;
}

bool hasNext() {