Skip to content

Commit 8b14963

Browse files
authored
Dynamic Programming LeetCode
1 parent 83a8471 commit 8b14963

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Stair_Climbing.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Top Down Approch
2+
vector<int> t (46 ,-1) ;
3+
class Solution {
4+
public:
5+
int climbStairs(int n) {
6+
//Top Down Approch
7+
if(n<=1) return t[n] = 1 ;
8+
if(t[n] != -1)
9+
return t[n] ;
10+
else return t[n] = climbStairs(n-1) + climbStairs(n-2);
11+
}
12+
};
13+
14+
//Bottom up Approch
15+
class Solution {
16+
public:
17+
int climbStairs(int n) {
18+
vector<int> t ={1,1} ;
19+
for(int i = 2 ; i <= n ;i++) t.push_back(t[i-1] +t[i-2]) ;
20+
return t[n] ;
21+
}
22+
};

0 commit comments

Comments
 (0)