剑指offer第七题(裴波那契数列)
来源:互联网 发布:修改sql触发器 编辑:程序博客网 时间:2024/06/15 05:03
n<=39
斐波那契数列:斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........
java代码:
public class Solution {
public int Fibonacci(int n) {
if(n<0){
return 0;
}
else if (n==1) {
return 1;
}
int result=0;
int temp =0;
int temp1=1;
for(int i=2;i<=n;i++){
result=temp+temp1;
temp=temp1;
temp1=result;
}
return result;
}
}
python代码:
# -*- coding:utf-8 -*-
class Solution:
def Fibonacci(self, n):
if n<=0:
return 0
if n==1:
return 1
a=0
b=1
for i in range(2,n+1):
result=a+b
a=b
b=result
return result
- 剑指offer第七题(裴波那契数列)
- 剑指offer第七题【斐波那契数列】c++实现
- 【剑指offer】裴波那契数列
- 【剑指offer】题9:裴波那契数列
- 【剑指offer】斐波那契数列
- 剑指offer--斐波那契数列
- 剑指Offer-斐波那契数列
- 剑指offer:斐波那契数列
- 《剑指offer》斐波那契数列
- 剑指 offer:斐波那契数列
- 【剑指Offer】斐波那契数列
- 剑指offer 斐波那契数列
- 【剑指offer】斐波那契数列
- 剑指offer 斐波那契数列
- [剑指offer]斐波那契数列
- 剑指offer|斐波那契数列
- 【剑指offer】斐波那契数列
- 剑指offer--斐波那契数列
- 结构体数组排序 (学生信息 按成绩排序 )
- c语言 指针
- java 之注解开发
- Scala IDE设置缩进格式
- 让你少写1,000行代码的表达式
- 剑指offer第七题(裴波那契数列)
- 在CentOS中安装arm-linux-gcc-4.5.1-v6-vfp-20101103.tgz交叉编译环境
- 线段树
- Java多线程四种创建方式
- 2018阿里校招笔试——给定一个字符串S和有效单词的字典D,请确定可以插入到S中的最小空格数,使得最终的字符串完全由D中的有效单词组成,并输出解。
- device_create创建设备节点分析
- [Leetcode]Median of Two Sorted Arrays
- 并行编程与计算平台 | NVIDIA CUDA | NVIDIA --- GPU编程
- (十一)外观模式详解(Service第三者插足,让action与dao分手)