Skip to content

Commit

Permalink
Create Find the Minimum Number of Fibonacci Numbers Whose Sum Is K.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizmann authored Apr 19, 2020
1 parent 7f2da7f commit 65b4a22
Showing 1 changed file with 19 additions and 0 deletions.
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


0 comments on commit 65b4a22

Please sign in to comment.