Skip to content

Commit 9446f15

Browse files
committed
Climbing Stairs DP Solution Added
1 parent 5144b36 commit 9446f15

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
You are climbing a staircase. It takes n steps to reach 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+
var climbStairs = function(n) {
7+
let arr = [n+1]
8+
arr[0] = 1;
9+
arr[1] = 1;
10+
for(let i = 2; i<n+1 ; i++){
11+
arr[i] = arr[i-1] + arr[i-2]
12+
}
13+
return arr[n]
14+
};

0 commit comments

Comments
 (0)