Skip to content

Commit aa09009

Browse files
authored
Create caroline.md
1 parent ec565a2 commit aa09009

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2018.11.27-leetcode125/caroline.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
题目详述
2+
大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。
3+
n<=39
4+
(这里的字体怎么调呀,要下什么插件吗,另外,斐波那契数列的第0项怎么是0,百科里面是1,这样婶儿的,斐波那契数列指的是这样一个
5+
数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........)
6+
7+
public class Solution{
8+
public int Fibonacci(int n){
9+
int a = 0;
10+
int b =1;
11+
if(n == 0)
12+
return 1;
13+
if(n == 1)
14+
return 1;
15+
int i=2;
16+
int sum=0;
17+
while(i<=n){
18+
sum = a+b;
19+
a=b;
20+
b=sum;
21+
i++;
22+
}
23+
return sum;
24+
}
25+
}

0 commit comments

Comments
 (0)