题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
递归,当青蛙跳到第n级台阶时,它要么从n-1跳一级要么从n-2级跳两个台阶,因此 f(n)=f(n-1)+f(n-2);当n=0时规定为1
public int jumpFloor(int target) {
if(target<0)return 0;
if(target==0||target==1) return 1;
return jumpFloor(target-1)+jumpFloor(target-2);
}
}