题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
先找规律
/*
斐波那契数列:
F(1)=1;
F(2)=2;
F(n)=F(n-1)+F(n-2);
可用递归
*/
public class Solution {
public int jumpFloor(int target) {
if(target==1)
return 1;
else if(target==2)
return 2;
else
return jumpFloor(target-1)+jumpFloor(target-2);
}
}