因为n级台阶,第一步有n种跳法:跳1级、跳2级、到跳n级
跳1级,剩下n-1级,则剩下跳法是f(n-1)
跳2级,剩下n-2级,则剩下跳法是f(n-2)
所以f(n)=f(n-1)+f(n-2)+...+f(1)
因为f(n-1)=f(n-2)+f(n-3)+...+f(1)
所以f(n)=2*f(n-1)

 

public class Solution {
    public int JumpFloorII(int target) {
        if(target<=0){
            return 0;
        }else if(target == 1){
            return 1;
        }else{
            return 2*(JumpFloorII(target-1));
        }
     }
}
posted on 2015-12-29 11:44  小飞虫子  阅读(275)  评论(0编辑  收藏  举报