题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
先了解跳台阶个数与调的次数之间的关系 通过推理得一个台阶有一种跳法,两个台阶有两种跳法,三个台阶有三种跳法,四个台阶有五种跳法,以此类推n个台阶有(n-1)+(n-2)中跳法,然后用递归求解方便很多。
public class Solution {
public int jumpFloor(int target) {
if(target == 1) {
return 1;
}
if(target == 2) {
return 2;
}
int tmp = 0;
if(target>=3) {
tmp = jumpFloor(target-1)+jumpFloor(target-2);
}
return tmp;
}
}