We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9665155 commit 41f23d7Copy full SHA for 41f23d7
climbing-stairs/froggy1014.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {number}
4
+ */
5
+var climbStairs = function(n) {
6
+ if (n === 1) return 1;
7
+ if (n === 2) return 2;
8
+
9
+ let dp = new Array(n + 1).fill(0);
10
+ dp[1] = 1;
11
+ dp[2] = 2;
12
+ for (let i = 3; i <= n; i++) {
13
+ dp[i] = dp[i - 1] + dp[i - 2];
14
+ }
15
+ return dp[n];
16
+};
17
18
19
+console.log(climbStairs(4));
0 commit comments