Created
April 20, 2020 02:20
-
-
Save ABHIINAV12/3d802f400b3799753f0b787d7961152a to your computer and use it in GitHub Desktop.
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
class Solution { | |
public: | |
int findMinFibonacciNumbers(int k) { | |
long long int arr[50]; | |
arr[1]=1; arr[2]=1; | |
for(int i=3;i<50;++i) | |
arr[i]=arr[i-1]+arr[i-2]; | |
int ret=0; | |
while(k!=0){ | |
ret++; | |
int l=1,h=49; | |
int poss=-1; | |
while(l<=h){ | |
int mid=l+(h-l)/2; | |
if(arr[mid]<=k){ | |
poss=mid; | |
l=mid+1; | |
}else{ | |
h=mid-1; | |
} | |
} | |
k-=arr[poss]; | |
} | |
return ret; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment