Skip to content

Commit a797748

Browse files
committed
斐波纳契数列
1 parent ef2ec95 commit a797748

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

fibonacci.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
# @param n: an integer
5+
# @return an integer f(n)
6+
def fibonacci(self, n):
7+
# write your code here
8+
if (n == 1) or (n == 2):
9+
return n - 1
10+
ret = 0
11+
f_1, f_2 = 0, 1
12+
for i in xrange(3, n + 1):
13+
ret = f_1 + f_2
14+
f_1 = f_2
15+
f_2 = ret
16+
return ret

0 commit comments

Comments
 (0)