这道题可以用非递归的方法来做
public class Solution { public int jumpFloor(int target) { if(target <= 2) return target; int cur = 0; int pre1 = 2; int pre2 = 1; for(int i=2; i<target ;i++){ cur = pre2 + pre1; pre2 = pre1; pre1 = cur; } return cur; } }
public class Solution { public int jumpFloor(int target) { if(target == 1) return 1; if(target == 2) return 2; return jumpFloor(target-1) + jumpFloor(target-2); } }