题解 | #跳台阶#
跳台阶
https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
public class Solution { public int jumpFloor(int target) { // int []dp = new int[target + 1]; //由于dp[2] = 2 且dp[1] = 1 则设dp[0]=1 //dp[0] = 1; //dp[1] = 1; //优化: 每次dp的运算都只需要前两个dp if(target <= 1 ) return 1; int a = 1; int b = 1; int temp = 0; for (int i = 2 ; i <= target ; i++) { // dp[i] = dp[i - 1] + dp[i - 2]; temp = a + b; a = b; b = temp; } // return dp[target]; return temp; } }