-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Find the Minimum Number of Fibonacci Numbers Whose Sum Is K.py
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Leetcode/Algorithm/python/Find the Minimum Number of Fibonacci Numbers Whose Sum Is K.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
MAXI = 10 ** 9 | ||
|
||
fibs = [1, 1] | ||
while fibs[-1] < MAXI: | ||
fibs.append(fibs[-1] + fibs[-2]) | ||
|
||
class Solution: | ||
def findMinFibonacciNumbers(self, k: int) -> int: | ||
ptr = len(fibs) - 1 | ||
res = 0 | ||
while k: | ||
# print(k, ptr, fibs[ptr]) | ||
if k >= fibs[ptr]: | ||
res += 1 | ||
k -= fibs[ptr] | ||
ptr -= 1 | ||
return res | ||
|
||
|