当前位置:网站首页>Sword finger offer (VII): Fibonacci sequence
Sword finger offer (VII): Fibonacci sequence
2022-07-26 13:18:00 【Konstanch】
solution 1: Recursion is easy to write , But there are serious efficiency problems .
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)
solution 2: loop
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
边栏推荐
- Kubernetes -- Introduction to common plug-ins of kubernetes
- 【TypeScript】TypeScript常用类型(上篇)
- LeetCode 1523. 在区间范围内统计奇数数目
- Display inline+calc realizes left, middle and right layout, and the middle is adaptive
- 维度灾难 维数灾难 暂记
- Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
- Today's sleep quality record 75 points
- Qualcomm once again "bet" on Zhongke Chuangda to challenge the full stack solution of intelligent driving software and hardware
- Square root of leetcode 69. x
- 目标检测网络R-CNN 系列
猜你喜欢

0 basic programming resources (collect first ~ read slowly ~)

多线程使用不当导致的 OOM

Chat system based on webrtc and websocket

panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)

1312_ Apply 7z command for compression and decompression

12-GuliMall 后台管理中商品系统的品牌管理

如何面对科技性失业?
Exploration on cache design optimization of community like business

(int argc, char** argv) command line parameters in visual stdio (VS)

【5G】5G中的CU和DU是什么?
随机推荐
Shutter cachednetworkimage fillet
基于WebRTC和WebSocket实现的聊天系统
基于Locust框架进行文件上传下载性能测试
B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
vector的一些实用操作
Guys, how can CDC Oracle set the reading from the specified SCN number, or how to set the read-only full archive, not to read fast
postgresql官网下载出错
Flutter textfield sets the height and automatically wraps lines, and the rounded border removes the underline
Leetcode 217. there are duplicate elements
pomerium
JSON格式执行计划(6)—mysql执行计划(五十二)
StreamNative 团队文化:一家“透明”的公司
B+ tree (5) introduction to MyISAM -- MySQL from getting started to mastering (17)
[upper computer tutorial] Application of integrated stepping motor and Delta PLC (as228t) under CANopen communication
Solution: unable to load the file c:\users\user\appdata\roaming\npm\npx PS1, because running scripts is prohibited on this system.
【TypeScript】TypeScript常用类型(上篇)
关于自动重复调用接口的一种实现方式-反射
MySQL可以自定义变参存储函数吗?
MySQL data directory (2) -- table data structure (XXV)
C regards type as generic type T and uses it as generic type of method