时间限制:1秒 空间限制:32768K 热度指数:255284
题目描述
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
思路:There are two cases of jumping and not jumping on each step (except the last one),so the answer is:2^(n-1).
class Solution {
public:
int jumpFloorII(int number) {
return pow(2,number-1);
}
};