Created
November 25, 2022 16:58
-
-
Save asen-ruuby/91b8e8b3b313e044ad12c20d19e5ac66 to your computer and use it in GitHub Desktop.
stairs
This file contains 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 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