1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/K 个不同整数的子数组 [subarrays-with-k-different-integers].html

37 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个正整数数组 <code>nums</code>和一个整数 <code>k</code>,返回 <code>nums</code> 中 「<strong>好子数组」</strong><em>&nbsp;</em>的数目。</p>
<p>如果 <code>nums</code>&nbsp;的某个子数组中不同整数的个数恰好为 <code>k</code>,则称 <code>nums</code>&nbsp;的这个连续、不一定不同的子数组为 <strong></strong><strong>好子数组 」</strong></p>
<ul>
<li>例如,<code>[1,2,3,1,2]</code> 中有&nbsp;<code>3</code>&nbsp;个不同的整数:<code>1</code><code>2</code>,以及&nbsp;<code>3</code></li>
</ul>
<p><strong>子数组</strong> 是数组的 <strong>连续</strong> 部分。</p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= nums[i], k &lt;= nums.length</code></li>
</ul>