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;
}
}
原文地址:https://www.cnblogs.com/singular/p/10019420.html
时间: 2024-10-08 02:56:19