[剑指offer]跳台阶
思路:
跳一节有一种,跳两节有两种,跳三节有f(1)+f(2)种,跳N节有f(N-1)+f(N-2)种,就是一个斐波那契数列。
实现:
public class Solution {
public int JumpFloor(int target) {
if(target<=2)return target;
int n1=1;
int n2=2;
int total=0;
for(int i=2;i<target;i++){
total=n1+n2;
n1=n2;
n2=total;
}
return total;
}
}