Created
November 18, 2020 02:19
-
-
Save lidangzzz/1fa7e9fdea20f8c2e47272410cb7e6ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
Function fibonacci | |
Author: lidangzzz | |
Input: x: number | |
Output: fibonacci of x | |
*/ | |
function fibonacci(x){ | |
if (x<0) return 0; | |
if (x==1 || x==0) return 1; | |
//elst x>=2 | |
let dp = [1,1] | |
for (let i=2;i<=x;i++){ let val = dp[dp.length-1] + dp[dp.length-2]; dp.push(val)} | |
return dp[x]; | |
} | |
for(let i=0;i<10;i++) print(fibonacci(i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment