2
#yyds干货盘点# 解决剑指offer:跳台阶扩展问题
source link: https://blog.51cto.com/u_15488507/5372403
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
#yyds干货盘点# 解决剑指offer:跳台阶扩展问题
原创1.简述:
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶(n为正整数)总共有多少种跳法。
数据范围:
进阶:空间复杂度 , 时间复杂度
2.代码实现:
public class Solution {
public int jumpFloorII(int target) {
int[] dp = new int[target + 1];
//初始化前面两个
dp[0] = 1;
dp[1] = 1;
//依次乘2
for(int i = 2; i <= target; i++)
dp[i] = 2 * dp[i - 1];
return dp[target];
}
}
public int jumpFloorII(int target) {
int[] dp = new int[target + 1];
//初始化前面两个
dp[0] = 1;
dp[1] = 1;
//依次乘2
for(int i = 2; i <= target; i++)
dp[i] = 2 * dp[i - 1];
return dp[target];
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK