Skip to content

Commit 04f9d2c

Browse files
committedApr 13, 2025
Add solution #1414
1 parent 5b9be55 commit 04f9d2c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,289 LeetCode solutions in JavaScript
1+
# 1,290 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1080,6 +1080,7 @@
10801080
1410|[HTML Entity Parser](./solutions/1410-html-entity-parser.js)|Medium|
10811081
1411|[Number of Ways to Paint N × 3 Grid](./solutions/1411-number-of-ways-to-paint-n-3-grid.js)|Hard|
10821082
1413|[Minimum Value to Get Positive Step by Step Sum](./solutions/1413-minimum-value-to-get-positive-step-by-step-sum.js)|Easy|
1083+
1414|[Find the Minimum Number of Fibonacci Numbers Whose Sum Is K](./solutions/1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k.js)|Medium|
10831084
1415|[The k-th Lexicographical String of All Happy Strings of Length n](./solutions/1415-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n.js)|Medium|
10841085
1422|[Maximum Score After Splitting a String](./solutions/1422-maximum-score-after-splitting-a-string.js)|Easy|
10851086
1431|[Kids With the Greatest Number of Candies](./solutions/1431-kids-with-the-greatest-number-of-candies.js)|Easy|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K
3+
* https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/
4+
* Difficulty: Medium
5+
*
6+
* Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k.
7+
* The same Fibonacci number can be used multiple times.
8+
*
9+
* The Fibonacci numbers are defined as:
10+
* - F1 = 1
11+
* - F2 = 1
12+
* - Fn = Fn-1 + Fn-2 for n > 2.
13+
*
14+
* It is guaranteed that for the given constraints we can always find such Fibonacci numbers
15+
* that sum up to k.
16+
*/
17+
18+
/**
19+
* @param {number} k
20+
* @return {number}
21+
*/
22+
var findMinFibonacciNumbers = function(k) {
23+
const fibonacci = [1, 1];
24+
while (fibonacci[fibonacci.length - 1] <= k) {
25+
fibonacci.push(fibonacci[fibonacci.length - 1] + fibonacci[fibonacci.length - 2]);
26+
}
27+
28+
let count = 0;
29+
let remaining = k;
30+
31+
for (let i = fibonacci.length - 1; i >= 0 && remaining > 0; i--) {
32+
while (fibonacci[i] <= remaining) {
33+
remaining -= fibonacci[i];
34+
count++;
35+
}
36+
}
37+
38+
return count;
39+
};

0 commit comments

Comments
 (0)
Please sign in to comment.