当前位置:网站首页>Lc: sword finger offer 10- I. Fibonacci series
Lc: sword finger offer 10- I. Fibonacci series
2022-07-23 06:04:00 【Seven percent】
Write a function , Input n , Fibonacci, please (Fibonacci) The number of the sequence n term ( namely F(N)). Fibonacci series is defined as follows :
F(0) = 0, F(1) = 1
F(N) = F(N - 1) + F(N - 2), among N > 1.
The Fibonacci series is composed of 0 and 1 Start , The Fibonacci number after that is the sum of the two numbers before .
The answer needs to be modelled 1e9+7(1000000007), If the initial result of calculation is :1000000008, Please return 1.
Example 1:
Input :n = 2
Output :1
Example 2:
Input :n = 5
Output :5
Method : Basic methods , Pay attention to mold taking .( I passed it ten times ,o(╥﹏╥)o)
class Solution {
public int fib(int n) {
int a=0;
int b=0;
int c=1;
if(n<2){
return n;
}
else{
for(int i=2;i<=n;i++){
a=b;
b=c;
c=(a+b)%1000000007;
}
return c;
}
}
}At the beginning, a recursion is written , As a result, the time exceeded the limit .( Cover your face and cry ) It still needs some technical content .
class Solution {
public int fib(int n) {
if(n==0){
return 0;
}
if(n==1){
return 1;
}
else{
return fib(n-1)+fib(n-2);
}
}
}边栏推荐
- Zstuacm summer camp flag bearer
- UNIX Programming - network socket
- Fiddler script personalized configuration display
- LC: Sword finger offer 03. repeated numbers in the array
- Determine whether the course exists in the set, and use the contains method
- 信息收集调研报告
- 【数据库连接】——节选自培训
- 嵌入式系统移植【3】——uboot的烧写及使用
- STM32学习—DHT11温湿度传感器采样驱动并用cjson格式上报
- A little life
猜你喜欢

栈溢出基础练习题——6(字符串漏洞64位下)

Firewall knowledge, principle, equipment, manufacturer research summary report

机器学习理论基础

03. Design of large-scale high parallel micro service system

Configure the private chirpstack of lorawan in the LAN

shell基本命令

从键盘输入一串字符,输出不同的字符以及每个字符出现的次数。(输出不按照顺序)运用String类的常用方法解题

mysql数据库基本知识
![[jmeter] solution to Chinese garbled response content](/img/ff/3d68a0cc34486e0b6cb35291ce10c0.png)
[jmeter] solution to Chinese garbled response content

DNS域名解析服务
随机推荐
esp-idf vscode配置 从下载工具链到创建工程,步骤记录
LC:剑指 Offer 05. 替换空格
[Research Report on the contents, methods, tools and results of information collection]
Common problems of multiple processes - how to lock the same parent thread variable (critical resource) when creating multiple threads so that the shared parent thread variable is not repeatedly modif
APUE process deeply understands fork and EXECL - obtain virtual machine IP address in program code
【基础8】——进程和线程
zy:修改主机名
[jmeter] solution to Chinese garbled response content
最近acm的一些感悟以及未来的一些想法
IA笔记1
NFS共享服务
快速支持客户知识库的核心优势是什么?
推荐系统基础架构以及项目介绍
文件目录权限
APUE进程深层理解fork和execl-程序代码里获取虚拟机IP地址
【基础3】——结构与函数
KMP
Tencent cloud is connected to lorawan and debugged
机器学习开发应用步骤的理解
LC: Sword finger offer 03. repeated numbers in the array