当前位置:网站首页>The step jumping expansion problem of sword finger offer
The step jumping expansion problem of sword finger offer
2022-07-26 18:22:00 【Morita Rinko】
Step jump expansion problem
Title Description :
A frog can jump up at a time 1 Stepped steps , You can jump on it 2 level …… It can also jump on n level . Ask the frog to jump on one n Steps of steps (n As a positive integer ) How many jumps are there in total ?
Problem solving :
f[0]=f[1]=1
f[n]=f[n-1]+f[n-2]+…+f[0]
because f[n-1]=f[n-2]+…+f[0]
therefore f[n]=2 * f[n-1]
Empathy f[n-1]=2 * f[n-2]
The resulting f[n]=2 * 2 * 2 * … * f[0]
Code :
class Solution {
public:
int jumpFloorII(int number) {
if(number==1 || number==0){
return 1;
}
int sum=1;
// because 0 and 1 All are 1 So it doesn't matter where you start
for(int i=1;i<number;i++){
// Left shift multiplication 2, Move right divided by 2
sum=sum<<1;
}
return sum;
}
};
边栏推荐
- 4、 Service communication principle, code implementation
- [unity3d] rocker
- LeetCode 0139. 单词拆分
- AI zhetianchuan ml unsupervised learning
- 链表-反转链表
- Simple uploading and downloading of Web project files
- 7、 Common commands of ROS (II): rosservice, rossrv, rosparam
- 《敏捷宣言》四大价值观,十二大原则
- 【翻译】为什么你需要一个API网关来管理对你的API的访问?
- AI zhetianchuan ml integrated learning
猜你喜欢

LeetCode50天刷题计划(Day 4—— 最长回文子串 14.00-16:20)

Vector CANoe Menu Plugin拓展入门

Relative path and absolute path

8.2 some algebraic knowledge (groups, cyclic groups and subgroups)

Kindergarten system based on SSM

Vector CANape - How to Send Receive CAN Message in CANape

The second set of 2020 American Asian individual match

BulletGraph(子弹图、项目符号图)

2、 Topic communication principle, code implementation

2022年的PMP考试大纲是什么?
随机推荐
AI zhetianchuan DL regression and classification
Detailed explanation of openwrt's feeds.conf.default
SSM练习第五天
LeetCode50天刷题计划(Day 3—— 串联所有单词的子串 10.00-13.20)
钉钉第三方服务商应用ISV应用开发及上架教程
ssm练习第二天_项目拆分moudle_基本增删改查_批量删除_一对一级联查询
ICML 2022 (Part 4) | | graph hierarchical alignment graph kernel to realize graph matching
During the oppo interview, 16 questions were thrown over. I was stupid
《圆圈正义》的信念
Spark data format unsafe row
LeetCode 0139. 单词拆分
分布式链路追踪Jaeger在Golang中的使用
Cross Site Request Forgery (CSRF)
[ Kitex 源码解读 ] 服务发现
PS_1_认识主界面_新建文档(分辨率)_打开保存(序列动画)
Bulletgraph (bullet diagram, bullet diagram)
Several ways to resolve hash conflicts
[Oumi reading club] talk about the creator economy in the meta universe: infinite dimension
How to become a better data scientist by learning to ask questions
LeetCode50天刷题计划(Day 4—— 最长回文子串 14.00-16:20)