mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>请你设计一个迭代器类 <code>CombinationIterator</code> ,包括以下内容:</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>CombinationIterator(string characters, int combinationLength)</code> 一个构造函数,输入参数包括:用一个 <strong>有序且字符唯一 </strong>的字符串 <code>characters</code>(该字符串只包含小写英文字母)和一个数字 <code>combinationLength</code> 。</li>
 | 
						||
	<li>函数 <em><code>next()</code> </em>,按 <strong>字典序 </strong>返回长度为 <code>combinationLength</code> 的下一个字母组合。</li>
 | 
						||
	<li>函数 <em><code>hasNext()</code> </em>,只有存在长度为 <code>combinationLength</code> 的下一个字母组合时,才返回 <code>true</code></li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>
 | 
						||
["CombinationIterator", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
 | 
						||
[["abc", 2], [], [], [], [], [], []]
 | 
						||
<strong>输出:</strong>
 | 
						||
[null, "ab", true, "ac", true, "bc", false]
 | 
						||
<strong>解释:
 | 
						||
</strong>CombinationIterator iterator = new CombinationIterator("abc", 2); // 创建迭代器 iterator
 | 
						||
iterator.next(); // 返回 "ab"
 | 
						||
iterator.hasNext(); // 返回 true
 | 
						||
iterator.next(); // 返回 "ac"
 | 
						||
iterator.hasNext(); // 返回 true
 | 
						||
iterator.next(); // 返回 "bc"
 | 
						||
iterator.hasNext(); // 返回 false
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= combinationLength <= characters.length <= 15</code></li>
 | 
						||
	<li> <code>characters</code> 中每个字符都 <strong>不同</strong></li>
 | 
						||
	<li>每组测试数据最多对 <code>next</code> 和 <code>hasNext</code> 调用 <code>10<sup>4</sup></code>次</li>
 | 
						||
	<li>题目保证每次调用函数 <code>next</code> 时都存在下一个字母组合。</li>
 | 
						||
</ul>
 |