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)/最长的斐波那契子序列的长度 [length-of-longest-fibonacci-subsequence].html
2022-03-29 12:43:11 +08:00

43 lines
2.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>如果序列 <code>X_1, X_2, ..., X_n</code> 满足下列条件,就说它是 <em>斐波那契式 </em>的:</p>
<ul>
<li><code>n >= 3</code></li>
<li>对于所有 <code>i + 2 <= n</code>,都有 <code>X_i + X_{i+1} = X_{i+2}</code></li>
</ul>
<p>给定一个<strong>严格递增</strong>的正整数数组形成序列 arr 找到 <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> 中最长的斐波那契式的子序列的长度。如果一个不存在返回  0 。</p>
<p><em>(回想一下,子序列是从原序列 <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> 中派生出来的,它从 <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>[3, 5, 8]</code> 是 <code>[3, 4, 5, 6, 7, 8]</code> 的一个子序列)</em></p>
<p> </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>示例 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> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 <= arr.length <= 1000</code></li>
<li>
<p><code>1 <= arr[i] < arr[i + 1] <= 10^9</code></p>
</li>
</ul>