题解 | #跳台阶#
跳台阶
https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
import java.util.*; //动态规划 //设置dp【n】为到达n阶的跳法数,状态转移方程为dp【n】 = dp【n-1】 + dp【n-2】 //因为n- 2阶和n-1都可以一步跳到n public class Solution { public int jumpFloor (int number) { if (number ==1){ return 1; }else if (number == 2){ return 2; } int[] dp = new int[number + 1 ]; dp[0] = 0; dp[1] = 1; dp[2] = 2; for (int i = 3; i <= number ; i++) { dp[i] = dp[i-2] + dp[i-1]; } return dp[number]; } }
动态规划题解 文章被收录于专栏
个人动态规划题解合集