mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-26 18:20:27 +08:00
53 lines
2.1 KiB
HTML
53 lines
2.1 KiB
HTML
<p>给你一个整数数组 <code>nums</code> 。</p>
|
||
|
||
<p>你的任务是找到 <code>nums</code> 中的 <strong>最长 <span data-keyword="subsequence-array">子序列</span></strong> <code>seq</code> ,这个子序列中相邻元素的 <strong>绝对差</strong> 构成一个 <strong>非递增</strong> 整数序列。换句话说,<code>nums</code> 中的序列 <code>seq<sub>0</sub></code>, <code>seq<sub>1</sub></code>, <code>seq<sub>2</sub></code>, ..., <code>seq<sub>m</sub></code> 满足 <code>|seq<sub>1</sub> - seq<sub>0</sub>| >= |seq<sub>2</sub> - seq<sub>1</sub>| >= ... >= |seq<sub>m</sub> - seq<sub>m - 1</sub>|</code> 。</p>
|
||
|
||
<p>请你返回这个子序列的长度。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">nums = [16,6,3]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>3</span></p>
|
||
|
||
<p><b>解释:</b></p>
|
||
|
||
<p>最长子序列是 <code>[16, 6, 3]</code> ,相邻绝对差值为 <code>[10, 3]</code> 。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [6,5,3,4,2,1]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>4</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>最长子序列是 <code>[6, 4, 2, 1]</code> ,相邻绝对差值为 <code>[2, 2, 1]</code> 。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 3:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [10,20,10,19,10,20]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>5</span></p>
|
||
|
||
<p><b>解释:</b></p>
|
||
|
||
<p>最长子序列是 <code>[10, 20, 10, 19, 10]</code> ,相邻绝对差值为 <code>[10, 10, 9, 9]</code> 。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= nums.length <= 10<sup>4</sup></code></li>
|
||
<li><code>1 <= nums[i] <= 300</code></li>
|
||
</ul>
|