mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
40 lines
1.7 KiB
HTML
40 lines
1.7 KiB
HTML
|
<p>给你一个整数数组 <code>nums</code> 和一个 <strong>非负</strong> 整数 <code>k</code> 。如果一个整数序列 <code>seq</code> 满足在范围下标范围 <code>[0, seq.length - 2]</code> 中存在 <strong>不超过</strong> <code>k</code> 个下标 <code>i</code> 满足 <code>seq[i] != seq[i + 1]</code> ,那么我们称这个整数序列为 <strong>好</strong> 序列。</p>
|
|||
|
|
|||
|
<p>请你返回 <code>nums</code> 中 <strong>好</strong> <span data-keyword="subsequence-array">子序列</span> 的最长长度</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong class="example">示例 1:</strong></p>
|
|||
|
|
|||
|
<div class="example-block">
|
|||
|
<p><span class="example-io"><b>输入:</b>nums = [1,2,1,1,3], k = 2</span></p>
|
|||
|
|
|||
|
<p><span class="example-io"><b>输出:</b>4</span></p>
|
|||
|
|
|||
|
<p><strong>解释:</strong></p>
|
|||
|
|
|||
|
<p>最长好子序列为 <code>[<em><strong>1</strong></em>,<em><strong>2</strong></em>,<strong><em>1</em></strong>,<em><strong>1</strong></em>,3]</code> 。</p>
|
|||
|
</div>
|
|||
|
|
|||
|
<p><strong class="example">示例 2:</strong></p>
|
|||
|
|
|||
|
<div class="example-block">
|
|||
|
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4,5,1], k = 0</span></p>
|
|||
|
|
|||
|
<p><span class="example-io"><b>输出:</b>2</span></p>
|
|||
|
|
|||
|
<p><strong>解释:</strong></p>
|
|||
|
|
|||
|
<p>最长好子序列为 <code>[<strong><em>1</em></strong>,2,3,4,5,<strong><em>1</em></strong>]</code> 。</p>
|
|||
|
</div>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>1 <= nums.length <= 5 * 10<sup>3</sup></code></li>
|
|||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
|||
|
<li><code>0 <= k <= min(50, nums.length)</code></li>
|
|||
|
</ul>
|