1286. Iterator for Combination
Medium
Design the CombinationIterator
class:
CombinationIterator(string characters, int combinationLength)
Initializes the object with a stringcharacters
of sorted distinct lowercase English letters and a numbercombinationLength
as arguments.next()
Returns the next combination of lengthcombinationLength
in lexicographical order.hasNext()
Returnstrue
if and only if there exists a next combination.
Example 1:
Constraints:
1 <= combinationLength <= characters.length <= 15
All the characters of
characters
are unique.At most
10^4
calls will be made tonext
andhasNext
.It is guaranteed that all calls of the function
next
are valid.
解題
Last updated