mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
44 lines
1.5 KiB
HTML
44 lines
1.5 KiB
HTML
给你一个整数数组 <code>nums</code> 和一个 <strong>正</strong> 整数 <code>k</code> 。
|
||
<p><code>nums</code> 的一个 <span data-keyword="subsequence-array">子序列</span> <code>sub</code> 的长度为 <code>x</code> ,如果其满足以下条件,则称其为 <strong>有效子序列</strong> :</p>
|
||
|
||
<ul>
|
||
<li><code>(sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k</code></li>
|
||
</ul>
|
||
返回 <code>nums</code> 的 <strong>最长</strong><strong>有效子序列</strong> 的长度。
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4,5], k = 2</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>5</span></p>
|
||
|
||
<p><b>解释:</b></p>
|
||
|
||
<p>最长有效子序列是 <code>[1, 2, 3, 4, 5]</code> 。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [1,4,2,3,1,4], k = 3</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>4</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>最长有效子序列是 <code>[1, 4, 1, 4]</code> 。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= nums.length <= 10<sup>3</sup></code></li>
|
||
<li><code>1 <= nums[i] <= 10<sup>7</sup></code></li>
|
||
<li><code>1 <= k <= 10<sup>3</sup></code></li>
|
||
</ul>
|