Skip to content

Instantly share code, notes, and snippets.

@lidangzzz
Last active November 16, 2020 02:30
Show Gist options
  • Save lidangzzz/86c78163bf7838220224530d6e36aec9 to your computer and use it in GitHub Desktop.
Save lidangzzz/86c78163bf7838220224530d6e36aec9 to your computer and use it in GitHub Desktop.
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