//很多人可能不能理解这为啥是斐波那契数列,我讲讲我的理解,勿喷
//N台阶的跳法其实就是在它前一台阶的基础上跳一下或者前两阶的基础上跳两下,别无它法。
public class Solution {
public int JumpFloor(int target) {
//首先要明白,这是一个斐波那契数列(f(n)是在f(n-1)和f(n-2)的基础上分别跳一步和跳两步上来的)
int last=1,last2=1,now=0;
if(target==1)return 1;
for(int i=0;i<target-1;i++)
{
now=last+last2;//本段避免使用数组的方法为借鉴csdn大神的操作,忘了帖出处
last=last2;
last2=now;
}
return now;
}
}