当前位置:网站首页>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;
}
};
边栏推荐
- VIM multiline operation
- PMP Exam details, what changes have been made to the new exam outline?
- LeetCode50天刷题计划(Day 5—— 最长回文子串 10.50-13:00)
- Quartz trigger rule
- 4、 Service communication principle, code implementation
- 2020美亚个人赛复盘
- Leetcode 50 day question brushing plan (day 4 - longest palindrome substring 14.00-16:20)
- 隐私计算基础组件系列-混淆电路
- 继续卷技术 埋头苦学,越学越会
- 【Unity3D】摇杆
猜你喜欢
随机推荐
[Digital IC] understand Axi Lite protocol in simple terms
推荐效果不如意,不如试试飞桨图学习
Nailing third-party service provider application ISV application development and listing tutorial
剑指offer 连续子数组的最大和(二)
ICML 2022(第四篇)|| 图分层对齐图核实现图匹配
PS_2_图层
立即报名 | 云原生技术交流 Meetup 广州站已开启,8 月 6 号与你相遇!
quartz触发器规则
Three ways of de duplication in SQL
8、 Topic communication: topic substitution and monitoring
成为测试/开发程序员,小张:现实就来了个下马威......
[translation] Why do you need an API gateway to manage access to your API?
SSH based online mall
How to assemble a registry?
Win10 连接无线不能输入密码字符,一输入就卡死
Drools basic grammar
Quartz trigger rule
It is said that the salary of Alibaba P7 is really fragrant
How to become a better data scientist by learning to ask questions
你适合做自动化 测试吗?









