mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
update
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<p>请你编写一个生成器函数,并返回一个可以生成 <strong>斐波那契数列</strong> 的生成器对象。</p>
|
||||
|
||||
<p><strong>斐波那契数列</strong> 的递推公式为 <code>X<sub>n</sub> = X<sub>n-1</sub> + X<sub>n-2</sub></code> 。</p>
|
||||
|
||||
<p>这个数列的前几个数字是 <code>0, 1, 1, 2, 3, 5, 8, 13</code> 。</p>
|
||||
|
||||
<p> </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> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= callCount <= 50</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user