Skip to content

Commit bb02823

Browse files
committed
[week2] climbing stairs sold
1 parent 932b4f5 commit bb02823

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climbing-stairs/Hong-Study.cpp

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

0 commit comments

Comments
 (0)