剑指09变态青蛙跳
题目描述
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
class Solution {
public:
int jumpFloorII(int number) {
int jumpFlo=1;
while(--number)
{
jumpFlo*=2;
}
return jumpFlo;
}
};
public class Solution {
public int JumpFloorII(int target) {
if (target<=0){
return -1;
}else if (target==1){
return 1;
}else {
return 2*JumpFloorII(target-1);
}
}
}
public int JumpFloorII(int target) {
if (target<=0){
return -1;
}else if (target==1){
return 1;
}else {
return 2*JumpFloorII(target-1);
}
}
}
# -*- coding:utf-8 -*-
class Solution:
def jumpFloorII(self, number):
# write code here
return 1<<(number-1)
class Solution:
def jumpFloorII(self, number):
# write code here
return 1<<(number-1)
·