topic
A frog can jump up to 1 step at a time, or jump up to 2 steps. Find the total number of jumping methods for the frog to jump on an n-level step (different order to calculate different results).
Code
public class Solution {
//动态规划的简单应用及斐波那契数列变体
public int JumpFloor(int target) {
if(target <= 2){
return target;
}
int first = 1;
int second = 2;
int temp = 0;
for(int i = 3; i <= target; i++ ){
temp = first + second;
first = second;
second = temp;
}
return temp;
}
}