递归:
public class Solution { public int JumpFloorII(int target) { if (target <= 0) { return 0; } else if (target == 1) { return 1; } else { return 2 * JumpFloorII(target - 1); } } }
动态规划:
public class Solution { public int JumpFloorII(int target) { if (target <= 0) { return 0; } if (target == 1) { return 1; } int x = 1; int y = 2; for (int i = 2; i <= target; i++) { y = 2 * x; x = y; } return y; } }
原文:https://www.cnblogs.com/s-star/p/12512819.html