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 6dff871 commit 0363257Copy full SHA for 0363257
climbing-stairs/kimyoung.js
@@ -0,0 +1,11 @@
1
+// found a pattern where the result is the addition of two previous elements,
2
+// but not sure if this is the expected answer
3
+var climbStairs = function (n) {
4
+ let arr = new Array(n).fill(1);
5
+ for (let i = 2; i <= n; i++) {
6
+ arr[i] = arr[i - 2] + arr[i - 1];
7
+ }
8
+ return n === 1 ? 1 : arr[n];
9
+};
10
+
11
+// time - O(n) iterate up to n times
0 commit comments