题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
斐波那契序列: dp(n) = dp(n-1) + dp(n-2)
class Solution {
public:
int jumpFloor(int number) {
if(number == 0)
return 0;
vector<int> dp(number + 3, 0);
dp[0] = dp[1] = 1;
for(int i = 2; i <= number; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[number];
}
};