Skip to content

Commit 473db1e

Browse files
authored
Create heozeop.cpp
1 parent a63a19b commit 473db1e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

climbing-stairs/heozeop.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time Complexity: O(n)
2+
// Spatial Complexity: O(n)
3+
4+
class Solution {
5+
public:
6+
int climbStairs(int n) {
7+
vector<int> dp(n + 1, 0);
8+
9+
if (n == 1) {
10+
return 1;
11+
}
12+
13+
dp[0] = dp[1] = 1;
14+
for(int i = 2; i <= n; ++i) {
15+
dp[i] = dp[i - 1] + dp[i - 2];
16+
}
17+
18+
return dp[n];
19+
}
20+
};

0 commit comments

Comments
 (0)