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)/生成斐波那契数列 [generate-fibonacci-sequence].html

38 lines
999 B
HTML
Raw Normal View History

2023-04-23 22:41:08 +08:00
<p>请你编写一个生成器函数,并返回一个可以生成 <strong>斐波那契数列</strong> 的生成器对象。</p>
<p><strong>斐波那契数列</strong> 的递推公式为 <code>X<sub>n</sub>&nbsp;= X<sub>n-1</sub>&nbsp;+ X<sub>n-2</sub></code></p>
<p>这个数列的前几个数字是 <code>0, 1, 1, 2, 3, 5, 8, 13</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>callCount = 5
<b>输出:</b>[0,1,1,2,3]
<strong>解释:</strong>
const gen = fibGenerator();
gen.next().value; // 0
gen.next().value; // 1
gen.next().value; // 1
gen.next().value; // 2
gen.next().value; // 3
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>callCount = 0
<strong>输出:</strong>[]
<b>解释:</b>gen.next() 永远不会被调用,所以什么也不会输出
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= callCount &lt;= 50</code></li>
</ul>