Files
leetcode-master/problems/0070.爬楼梯.md
youngyangyang04 2da3dacb25 Update
2020-12-01 09:16:49 +08:00

20 lines
399 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

dp里求排列1 2 步 和 2 1 步都是上三个台阶,但不一样!
这是求排列
```
class Solution {
public:
int climbStairs(int n) {
vector<int> dp(n + 1, 0);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
if (i - j >= 0) dp[i] += dp[i - j];
}
}
return dp[n];
}
};
```