题解 | #斐波那契数列#

斐波那契数列

http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3

//递归
/**
*

*   @param n int整型
*   @return int整型
*   /
int Fibonacci(int n) {
if (n==0)```
return 0;
```if (n==1)```
return 1;
```return Fibonacci(n-1)+Fibonacci(n-2);
}

//非递归
int Fibonacci(int n) {
int a=0,b=1;
if (n==0)
return 0;
if (n==1)
return 1;
while (n>=2)
{
b=a+b;
a=b-a;
    n--;
}
return b;
}
全部评论

相关推荐

06-11 13:34
门头沟学院 C++
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务