1286. Iterator for Combination
https://leetcode.com/problems/iterator-for-combination
Description
Design the CombinationIterator class:
CombinationIterator(string characters, int combinationLength)Initializes the object with a stringcharactersof sorted distinct lowercase English letters and a numbercombinationLengthas arguments.next()Returns the next combination of lengthcombinationLengthin lexicographical order.hasNext()Returnstrueif and only if there exists a next combination.
Example 1:
**Input**
["CombinationIterator", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
[["abc", 2], [], [], [], [], [], []]
**Output**
[null, "ab", true, "ac", true, "bc", false]
**Explanation**
CombinationIterator itr = new CombinationIterator("abc", 2);
itr.next(); // return "ab"
itr.hasNext(); // return True
itr.next(); // return "ac"
itr.hasNext(); // return True
itr.next(); // return "bc"
itr.hasNext(); // return FalseConstraints:
1 <= combinationLength <= characters.length <= 15All the characters of
charactersare unique.At most
104calls will be made tonextandhasNext.It's guaranteed that all calls of the function
nextare valid.
ac
Previous1285. Find the Start and End Number of Continuous RangesNext1287. Element Appearing More Than 25% In Sorted Array
Last updated
Was this helpful?