Skip to content

Instantly share code, notes, and snippets.

@asen-ruuby
Created November 25, 2022 16:58
Show Gist options
  • Save asen-ruuby/91b8e8b3b313e044ad12c20d19e5ac66 to your computer and use it in GitHub Desktop.
Save asen-ruuby/91b8e8b3b313e044ad12c20d19e5ac66 to your computer and use it in GitHub Desktop.
stairs
function F(n) {
if (n < 0) {
return 0;
}
if (n === 0) {
return 1;
}
return F(n - 1) + F(n - 2);
}
function climbStairs(n) {
const dpTable = [1, 1];
for (let i = 2; i <= n; i++) {
dpTable[i] = dpTable[i - 1] + dpTable[i - 2];
}
return dpTable[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment