mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
47 lines
1.1 KiB
HTML
47 lines
1.1 KiB
HTML
<p><strong>斐波那契数</strong> (通常用 <code>F(n)</code> 表示)形成的序列称为 <strong>斐波那契数列</strong> 。该数列由 <strong>0</strong> 和 <strong>1</strong> 开始,后面的每一项数字都是前面两项数字的和。也就是:</p>
|
||
|
||
<pre>
|
||
F(0) = 0,F(1) = 1
|
||
F(n) = F(n - 1) + F(n - 2),其中 n > 1
|
||
</pre>
|
||
|
||
<p>给定 <code>n</code> ,请计算 <code>F(n)</code> 。</p>
|
||
|
||
<p>答案需要取模 1e9+7(1000000007) ,如计算初始结果为:1000000008,请返回 1。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 2
|
||
<strong>输出:</strong>1
|
||
<strong>解释:</strong>F(2) = F(1) + F(0) = 1 + 0 = 1
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3
|
||
<strong>输出:</strong>2
|
||
<strong>解释:</strong>F(3) = F(2) + F(1) = 1 + 1 = 2
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 4
|
||
<strong>输出:</strong>3
|
||
<strong>解释:</strong>F(4) = F(3) + F(2) = 2 + 1 = 3
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>0 <= n <= 100</code></li>
|
||
</ul>
|
||
|
||
<p> </p>
|