forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1286.java
More file actions
29 lines (23 loc) · 719 Bytes
/
1286.java
File metadata and controls
29 lines (23 loc) · 719 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
class CombinationIterator {
public CombinationIterator(String ch, int l) {
combine(0, l, new StringBuilder(), ch);
}
private Queue<String> q = new LinkedList();
private void combine(int s, int k, StringBuilder cur, String ch) {
if (cur.length() == k) {
q.offer(cur.toString());
return;
}
for (int i = s; i <= ch.length() - (k - cur.length()); i++) {
cur.append(ch.charAt(i));
combine(i + 1, k, cur, ch);
cur.deleteCharAt(cur.length() - 1);
}
}
public String next() {
return q.poll();
}
public boolean hasNext() {
return !q.isEmpty();
}
}