当前位置:网站首页>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
边栏推荐
- The best engineer was "forced" away by you like this!
- [applet] why can't the onreachbottom event be triggered? (one second)
- Mysql数据目录(3)---表数据结构myISAM(二十六)
- Slam 02. overall framework
- 目标检测网络R-CNN 系列
- B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
- B+树挑选索引(2)---mysql从入门到精通(二十三)
- From January to June, China's ADAS suppliers accounted for 9%, and another parts giant comprehensively laid out the new smart drive track
- Student examination system based on C #
- B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
猜你喜欢

基于Locust框架进行文件上传下载性能测试

Learn about Pinia state getters actions plugins
![[5gc] what is 5g slice? How does 5g slice work?](/img/8c/52ba57d6a18133e97fa00b6a7cf8bc.png)
[5gc] what is 5g slice? How does 5g slice work?

Probability theory and mathematical statistics

Hcip day 11 comparison (BGP configuration and release)
![[5g] what are Cu and Du in 5g?](/img/5b/3453ade88ded4593edfcba9beb8ada.jpg)
[5g] what are Cu and Du in 5g?

AI theory knowledge map 1 Foundation

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

JVM: what does the class loading subsystem do? What is it made of? What eight part essay do you need to remember?

Dimension disaster dimension disaster suspense
随机推荐
同站攻击(相关域攻击)论文阅读 Can I Take Your Subdomain?Exploring Same-Site Attacks in the Modern Web
同花顺开的账户安全吗?
AI-理论-知识图谱1-基础
基于Bézier曲线的三维造型与渲染
[5gc] what is 5g slice? How does 5g slice work?
How to face scientific and technological unemployment?
为什么要做“密评”?
Kubernetes APIServer 限流策略
LeetCode 217. 存在重复元素
Precautions for triggering pytest.main() from other files
Bitwise and how to write SQL
Outline design specification
Display inline+calc realizes left, middle and right layout, and the middle is adaptive
Probability theory and mathematical statistics
Panorama of volcanic engine cloud growth plan: 30 + plans come out together, and military development advantage areas
HCIP第十一天比较(BGP的配置、发布)
Flutter textfield sets the height and automatically wraps lines, and the rounded border removes the underline
JSON format execution plan (6) - MySQL execution plan (52)
二叉树的初阶笔记
0 basic programming resources (collect first ~ read slowly ~)