[CareerCup] 9.1 Climbing Staircase 爬楼梯

9.1 A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.

LeetCode上的原题,请参见我之前的博客Climbing Stairs 爬*问题

class Solution {
public:
int countWays(int n) {
vector<int> res(n + , );
for (int i = ; i <= n; ++i) {
res[i] = res[i - ] + res[i - ];
}
return res.back();
}
};
上一篇:nginx的一次工作记录


下一篇:day16 初识面向对象