公式法
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param number int整型
* @return int整型
*/
int jumpFloorII(int number) {
// write code here
// 1 2 4 8
// 1 2 3 4
return pow(2,number-1);
}
};
动态规划
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param number int整型
* @return int整型
*/
int arr[20]={0};
int jumpFloorII(int number) {
// write code here
//1,1+1, 1+2+1,
//1, a[1]+1, a[1]+a[2]+1
arr[0]=1;
for(int i=1;i<number;i++)
{
arr[i]=2*arr[i-1];
}
return arr[number-1];
}
};