forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1286.cpp
More file actions
35 lines (31 loc) · 623 Bytes
/
1286.cpp
File metadata and controls
35 lines (31 loc) · 623 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class CombinationIterator
{
public:
CombinationIterator(string ch, int l)
{
combine(0, l, "", ch);
}
string next()
{
string res = q.front();
q.pop();
return res;
}
bool hasNext()
{
return !q.empty();
}
private:
queue<string> q;
void combine(int s, int k, string cur, string& ch)
{
if (cur.size() == k) {
q.push(cur);
return;
}
for (int i = s; i <= ch.size() - (k - cur.size()); i++)
{
combine(i + 1, k, cur + ch[i], ch);
}
}
};