标签:剑指offer for ret 斐波那契数 bsp return class public nbsp
public class Solution {
public int Fibonacci(int n) {
//错误输入处理
if(n<0) return -1;
int pre = 1;
int result = 0;
for(int i=0; i<n; i++){
//计算第i项
result += pre;
//将pre往后更新一项
pre = result - pre;
}
return result;
}
}
标签:剑指offer for ret 斐波那契数 bsp return class public nbsp
原文地址:https://www.cnblogs.com/singular/p/10019420.html