mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个正整数数组 <code>nums</code>和一个整数 <font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.6px"><span style="background-color:#f9f2f4">k</span></span></font></font> ,返回 <font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.6px"><span style="background-color:#f9f2f4">num</span></span></font></font> 中 「<strong>好子数组」</strong><em> </em>的数目。</p>
 | 
						||
 | 
						||
<p>如果 <code>nums</code> 的某个子数组中不同整数的个数恰好为 <code>k</code>,则称 <code>nums</code> 的这个连续、不一定不同的子数组为 <strong>「</strong><strong>好子数组 」</strong>。</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>例如,<code>[1,2,3,1,2]</code> 中有 <code>3</code> 个不同的整数:<code>1</code>,<code>2</code>,以及 <code>3</code>。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p><strong>子数组</strong> 是数组的 <strong>连续</strong> 部分。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [1,2,1,2,3], k = 2
 | 
						||
<strong>输出:</strong>7
 | 
						||
<strong>解释:</strong>恰好由 2 个不同整数组成的子数组:[1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [1,2,1,3,4], k = 3
 | 
						||
<strong>输出:</strong>3
 | 
						||
<strong>解释:</strong>恰好由 3 个不同整数组成的子数组:[1,2,1,3], [2,1,3], [1,3,4].
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
 | 
						||
	<li><code>1 <= nums[i], k <= nums.length</code></li>
 | 
						||
</ul>
 |