面试题10.3-变态跳台阶

  • 题目

一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。

  • 代码
public class Solution {
    public int JumpFloorII(int target) {
         if(target==0){
             return 0;
         }
        if(target==1){
            return 1;
        }
        if(target==2){
            return 2;
        }
        int res=2;
        for(int i=3;i<=target;i++){
            res=res*2;
        }
        return res;
    }
    }

  

猜你喜欢

转载自www.cnblogs.com/moonlightml/p/9827801.html
今日推荐