JZ71 跳台阶扩展问题
跳台阶扩展问题_牛客题霸_牛客网 (nowcoder.com)
// //递归
// public class Solution {
// public int jumpFloorII(int target) {
// if(target==0) return 1;
// if(target==1) return 1;
// return 2*jumpFloorII(target-1);
// }
// }
//动规
public class Solution {
public int jumpFloorII(int target) {
if(target==0) return 1;
if(target==1) return 1;
int[] dp=new int[target+1];
dp[0]=1;
dp[1]=1;
for(int i=2;i<=target;i++){
dp[i]=2*dp[i-1];
}
return dp[target];
}
}