topic
A frog can jump 1 step at a time, or 2 steps ... it can also jump to n levels. Ask the frog how many ways to jump on an n-level step.
Code
public class Solution {
//每个台阶都有跳与不跳两种情况(除了最后一个台阶),最后一个台阶必须跳。所以共2^(n-1)中情况
public int JumpFloorII(int target) {
if(target < 2){
return target;
}else{
int result = 2;
for(int i = 2; i < target; i++){
result = result*2;
}
return result;
}
}
}