1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 17:05:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/最长的斐波那契子序列的长度 [length-of-longest-fibonacci-subsequence].html
2025-09-29 14:43:44 +08:00

43 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<sub>1</sub>, x<sub>2</sub>, ..., x<sub>n</sub></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<sub>i</sub>&nbsp;+ x<sub>i+1</sub>&nbsp;== x<sub>i+2</sub></code></li>
</ul>
<p>给定一个&nbsp;<strong>严格递增&nbsp;</strong>的正整数数组形成序列 <code>arr</code>&nbsp;,找到 <code><font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.600000381469727px"><span style="caret-color:#c7254e"><span style="background-color:#f9f2f4">arr</span></span></span></font></font></code>&nbsp;中最长的斐波那契式的子序列的长度。如果不存在,返回&nbsp;&nbsp;<code>0</code></p>
<p><strong>子序列</strong> 是通过从另一个序列 <code>arr</code> 中删除任意数量的元素(包括删除 0 个元素)得到的,同时不改变剩余元素顺序。例如,<code>[3, 5, 8]</code><code>[3, 4, 5, 6, 7, 8]</code>&nbsp;的子序列。</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<sup>9</sup></code></p>
</li>
</ul>