1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最长斐波那契数列 [Q91FMA].html
2022-03-29 12:43:11 +08:00

47 lines
1.8 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>如果序列&nbsp;<code>X_1, X_2, ..., X_n</code>&nbsp;满足下列条件,就说它是&nbsp;<em>斐波那契式&nbsp;</em>的:</p>
<ul>
<li><code>n &gt;= 3</code></li>
<li>对于所有&nbsp;<code>i + 2 &lt;= n</code>,都有&nbsp;<code>X_i + X_{i+1} = X_{i+2}</code></li>
</ul>
<p>给定一个<strong>严格递增</strong>的正整数数组形成序列 <code>arr</code>&nbsp;,找到 <code>arr</code> 中最长的斐波那契式的子序列的长度。如果一个不存在,返回&nbsp;&nbsp;0 。</p>
<p><em>(回想一下,子序列是从原序列&nbsp; <code>arr</code> 中派生出来的,它从 <code>arr</code> 中删掉任意数量的元素(也可以不删),而不改变其余元素的顺序。例如,&nbsp;<code>[3, 5, 8]</code>&nbsp;&nbsp;<code>[3, 4, 5, 6, 7, 8]</code>&nbsp;的一个子序列)</em></p>
<p>&nbsp;</p>
<ul>
</ul>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入: </strong>arr =<strong> </strong>[1,2,3,4,5,6,7,8]
<strong>输出: </strong>5
<strong>解释: </strong>最长的斐波那契式子序列为 [1,2,3,5,8] 。
</pre>
<p><strong>示例&nbsp;2</strong></p>
<pre>
<strong>输入: </strong>arr =<strong> </strong>[1,3,7,11,12,14,18]
<strong>输出: </strong>3
<strong>解释</strong>: 最长的斐波那契式子序列有 [1,11,12]、[3,11,14] 以及 [7,11,18] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= arr.length &lt;= 1000</code></li>
<li>
<p><code>1 &lt;= arr[i] &lt; arr[i + 1] &lt;= 10^9</code></p>
</li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 873&nbsp;题相同:&nbsp;<a href="https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/">https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/</a></p>