Fibonacci Number || Leetcode 509 || 4 Ways || O(1) Solution

preview_player
Показать описание
O(1) Solution Code :

*Binet's formula*

int fib(int n){
double gloden_mean=(1+sqrt(5))/2;
double golden_ratio=(1-sqrt(5))/2;
return (pow(gloden_mean,n)-pow(global_ratio,n))/sqrt(5);
}
Рекомендации по теме