如果一行代码能解决,为啥不呢?
分析:
假设走阶楼梯有
种走法,则
。
可知:
所以一行代码搞定
class Solution {
public:
int jumpFloorII(int number) {
return 1 << (number - 1);
}
};分析:
假设走阶楼梯有
种走法,则
。
可知:
所以一行代码搞定
class Solution {
public:
int jumpFloorII(int number) {
return 1 << (number - 1);
}
};相关推荐