当前位置:网站首页>Brush the title "sword finger offer" day03
Brush the title "sword finger offer" day03
2022-07-27 09:43:00 【Pac Man programming】
Title source : Power button 《 The finger of the sword Offer》 The second edition
Completion time :2022/07/24
List of articles
10- I. Fibonacci sequence

My explanation
class Solution {
public:
int fib(int n) {
if(n == 0 || n == 1){
return n;
}
int a = 0,b = 1,count = 1;
while(count != n){
int res = (a + b) % 1000000007;
a = b;
b = res;
count++;
}
return b;
}
};
10- II. The problem of frog jumping on the steps

My explanation
This problem is almost the same as Fibonacci series , At first I didn't think of it , Read the solution in the book . You can choose to jump every time you jump on the steps 1 Grade or 2 level , therefore n The jumping method of steps is f(n-1) + f(n-2) Kind of . Except for the initial f(0) Not the same , All the others can be applied to the previous question .
class Solution {
public:
int numWays(int n) {
if(n == 0 || n == 1){
return 1;
}
int a = 1,b = 1,count = 1;
while(count != n){
int res = (a + b) % 1000000007;
a = b;
b = res;
count++;
}
return b;
}
};
边栏推荐
- 如果mysql磁盘满了,会发生什么?还真被我遇到了!
- 7/26 思维+dp+后缀数组的学习
- I grabbed a ticket and thought I found the system bug of 12306
- 七月集训(第19天) —— 二叉树
- 35 spark streaming backpressure mechanism, spark data skew solution and kylin's brief introduction
- The command prompt cannot start mysql, prompting system error 5. Access denied. terms of settlement
- 2016展望
- 吃透Chisel语言.24.Chisel时序电路(四)——Chisel内存(Memory)详解
- Nine ways to read the file path under the resources directory
- Nacos配置中心动态刷新数据源
猜你喜欢
![[Wuhan University of technology] information sharing for the preliminary and second examinations of postgraduate entrance examination](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Wuhan University of technology] information sharing for the preliminary and second examinations of postgraduate entrance examination

XML概述

给自己写一个年终总结,新年快乐!

Lua function nested call

1344. Included angle of clock pointer

Understand chisel language. 24. Chisel sequential circuit (IV) -- detailed explanation of chisel memory

华为交换机双上行组网Smart-link配置指南

Understand chisel language. 27. Chisel advanced finite state machine (I) -- basic finite state machine (Moore machine)

Nccl collective communication --collective operations

Quick apply custom progress bar
随机推荐
Towards the peak of life
Monitoring artifact: Prometheus easy to get started, really fragrant!
At the end of the year, I'll teach you how to get high performance!
七月集训(第04天) —— 贪心
快应用自定义进度条
一骑入秦川——浅聊Beego AutoRouter是如何工作
In depth analysis, sub database and sub table are the most powerful auxiliary sharding sphere
2022 software test interview questions 200 big factory interview true questions brushed to get 10K positions
会议OA项目之会议排座功能&&会议送审的实现
July training (day 18) - tree
Nine ways to read the file path under the resources directory
拟搬迁!211中国石油大学(华东)新校区,正式启用!
七月集训(第21天) —— 堆(优先队列)
ESP8266-Arduino编程实例-中断
Google Earth engine app - print the coordinates of points to the console and map, set the style and update it
[raspberry pie] box related manual-4 web agent
七月集训(第26天) —— 并查集
It's great to write code for 32 inch curved screen display! Send another one!
July training (day 13) - two way linked list
I grabbed a ticket and thought I found the system bug of 12306