斐波那契数列无需递归:
public class Solution {
public int Fibonacci(int n) {
int a = 0, b = 1;
for (int i = 1; i <= n; i++) {
a = a + b;
b = a - b;
}
return a;
}
}
public class Solution {
public int Fibonacci(int n) {
int a = 0, b = 1;
for (int i = 1; i <= n; i++) {
a = a + b;
b = a - b;
}
return a;
}
}
全部评论
相关推荐
11-26 09:40
莆田学院 产品经理 点赞 评论 收藏
分享