forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1286.js
More file actions
31 lines (29 loc) · 638 Bytes
/
1286.js
File metadata and controls
31 lines (29 loc) · 638 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
/**
* @param {string} characters
* @param {number} combinationLength
*/
var CombinationIterator = function(ch, l) {
this.res = [];
var combine = (s, cur) => {
if (cur.length == l) {
this.res.push(cur);
return;
}
for (let i = s; i <= ch.length - (l - cur.length); i++) {
combine(i + 1, cur + ch[i]);
}
}
combine(0, "");
};
/**
* @return {string}
*/
CombinationIterator.prototype.next = function() {
return this.res.shift();
};
/**
* @return {boolean}
*/
CombinationIterator.prototype.hasNext = function() {
return this.res.length != 0;
};