class Solution {
public:
int Fibonacci(int n) {
int ans = 0;
int a = 0,b = 1;
if(n == 0){
return 0;
}else if(n == 1){
return 1;
}else{
for(int i = 2;i <= n;i++){
ans = a + b;
a = b;
b = ans;
}
return ans;
}
}
};
剑指offer系列——斐波那契数列
猜你喜欢
转载自blog.csdn.net/qwer7512090/article/details/104910136
今日推荐
周排行