Last active
November 16, 2020 02:30
-
-
Save lidangzzz/86c78163bf7838220224530d6e36aec9 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(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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment