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; } }
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