当前位置:网站首页>剑指Offer(七):斐波那契数列
剑指Offer(七):斐波那契数列
2022-07-26 10:35:00 【康斯坦奇】
解法1:这道题递归很好写,但是存在很严重的效率问题。
class Solution:
def Fibonacci(self, n):
# write code here
if n == 0:
return 0
if n == 1:
return 1
return self.Fibonacci(n-2)+self.Fibonacci(n-1)
解法2:循环
class Solution:
def Fibonacci(self, n):
# write code here
if n <= 1:
return n
a = 0
b = 1
c = 0
for i in range(2,n+1):
c = a + b
a = b
b = c
return c
边栏推荐
- 记给esp8266烧录刷固件
- 数据分析入门 | kaggle泰坦尼克任务
- 粽子大战 —— 猜猜谁能赢
- 反射机制简述
- [leetcode每日一题2021/4/23]368. 最大整除子集
- .NET操作Redis Set无序集合
- Redis special data type usage scenarios
- Parallelism, concurrency and several directions for high concurrency optimization
- Navicat15连接本地虚拟机的Mysql(Centos7)
- .net5wtm (asp.net core) PgSQL unpacking operation
猜你喜欢

Dry goods likeshop takeout order system is open source, 100% open source, no encryption

2022/07/25 ------ arrangement of strings

canvas上传图片base64-有裁剪功能-Jcrop.js

Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
![[Halcon vision] threshold segmentation](/img/1c/e2463a796f99804a55680b69e714a6.png)
[Halcon vision] threshold segmentation

Tradingview tutorial

vscode上使用anaconda(已经配置好环境)

404页面和路由钩子

Phase 4: one of College Students' vocational skills preparation in advance

多目标优化系列1---NSGA2的非支配排序函数的讲解
随机推荐
超图 影像 如何去除黑边(两种方法)
记给esp8266烧录刷固件
10 令 operator= 返回一个 reference to *this
Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
(转载)ArcGIS Engine中各种点的创建方法
GIS方法类期刊和论文的综述(Introduction)怎么写?
The problem of large fluctuation of hx711 data
Issue 7: how do you choose between curling up and lying flat
干货likeshop外卖点餐系统开源啦100%开源无加密
并行、并发及对于高并发优化的几个方向
[Halcon vision] programming logic
The difference between equals and = =
如何实现临时的图形要素现实
.NET 开源框架在工业生产中的应用
[C language] named type and anonymous type
Redis implementation of distributed lock solution
[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组
Inheritance method of simplified constructor (I) - combined inheritance
.NET操作Redis List列表
少了个分号