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 af081a2 commit 6275b70Copy full SHA for 6275b70
Dynamic-Programming/ClimbingStairs.js
@@ -0,0 +1,26 @@
1
+/*
2
+ * You are climbing a stair case. It takes n steps to reach to the top.
3
+ * Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
4
+*/
5
+
6
+const climbStairs = (n) => {
7
+ let prev = 0
8
+ let cur = 1
9
+ let temp
10
11
+ for (let i = 0; i < n; i++) {
12
+ temp = prev
13
+ prev = cur
14
+ cur += temp
15
+ }
16
+ return cur
17
+}
18
19
+const main = () => {
20
+ const number = 5
21
22
+ console.log('Number of ways to climb ' + number + ' stairs in ' + climbStairs(5))
23
24
25
+// testing
26
+main()
0 commit comments