题解 | #跳台阶#
跳台阶
https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
public class Solution { public int jumpFloor(int target) { // 存储上一步的步数,target指的索引,索引+1是数组长度 int[] dp = new int[target + 1]; if (target == 0) { return 0; } else if (target == 1) { return 1; } else if (target == 2) { return 2; } dp[0] = 0; dp[1] = 1; dp[2] = 2; for (int i = 3; i <= target; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } return dp[target]; } }
解题思想:动态规划,由已知求未知,同时dp数组存储已知值,求最终值。
#算法##算法笔记#