File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -527,6 +527,7 @@ Solutions to LeetCode problems. The first column links to the problem in LeetCod
527
527
| [ 2635. Apply Transform Over Each Element in Array] [ lc2635 ] | 🟢 Easy | [ ![ js] ( res/js.png )] [ lc2635js ] |
528
528
| [ 2636. Promise Pool] [ lc2636 ] | 🟠 Medium | [ ![ js] ( res/js.png )] [ lc2636js ] |
529
529
| [ 2637. Promise Time Limit] [ lc2637 ] | 🟢 Easy | [ ![ js] ( res/js.png )] [ lc2637js ] |
530
+ | [ 2648. Generate Fibonacci Sequence] [ lc2648 ] | 🟢 Easy | [ ![ js] ( res/js.png )] [ lc2648js ] |
530
531
| [ 2665. Counter II] [ lc2665 ] | 🟢 Easy | [ ![ js] ( res/js.png )] [ lc2665js ] |
531
532
| [ 2666. Allow One Function Call] [ lc2666 ] | 🟢 Easy | [ ![ js] ( res/js.png )] [ lc2666js ] |
532
533
| [ 2667. Create Hello World Function] [ lc2667 ] | 🟢 Easy | [ ![ js] ( res/js.png )] [ lc2667js ] |
@@ -1680,6 +1681,8 @@ Solutions to LeetCode problems. The first column links to the problem in LeetCod
1680
1681
[ lc2636js ] : leetcode/promise-pool.js
1681
1682
[ lc2637 ] : https://leetcode.com/problems/promise-time-limit/
1682
1683
[ lc2637js ] : leetcode/promise-time-limit.js
1684
+ [ lc2648 ] : https://leetcode.com/problems/generate-fibonacci-sequence/
1685
+ [ lc2648js ] : leetcode/generate-fibonacci-sequence.js
1683
1686
[ lc2665 ] : https://leetcode.com/problems/counter-ii/
1684
1687
[ lc2665js ] : leetcode/counter-ii.js
1685
1688
[ lc2666 ] : https://leetcode.com/problems/allow-one-function-call/
Original file line number Diff line number Diff line change
1
+ // 2648. Generate Fibonacci Sequence
2
+ // 🟢 Easy
3
+ //
4
+ // https://leetcode.com/problems/generate-fibonacci-sequence/
5
+ //
6
+ // Tags: Javascript
7
+
8
+ // A generator that builds its next value as the sum of the previous two.
9
+ //
10
+ // Time complexity: O(n) - Each call takes O(1), n calls will take O(n)
11
+ // Space complexity: O(1) - The generator only stores two number values.
12
+ //
13
+ // Runtime 58 ms Beats 56.65%
14
+ // Memory 41.3 MB Beats 97.60%
15
+ /**
16
+ * @return {Generator<number> }
17
+ */
18
+ var fibGenerator = function * ( ) {
19
+ let cur = 0 ;
20
+ let next = 1 ;
21
+ while ( true ) {
22
+ next = cur + next ;
23
+ cur = next - cur ;
24
+ yield next - cur ;
25
+ }
26
+ } ;
27
+
28
+ /**
29
+ * const gen = fibGenerator();
30
+ * gen.next().value; // 0
31
+ * gen.next().value; // 1
32
+ */
You can’t perform that action at this time.
0 commit comments