题解 | #斐波那契数列#--利用数组
斐波那契数列
https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @return int整型
*/
public int Fibonacci (int n) {
// write code here
if (n == 1 || n == 2) return 1;
Integer[] results = new Integer[n];
results[0] = 1;
results[1] = 1;
for (int i = 2; i < n; i++) {
results[i] = results[i - 1] + results[i - 2];
}
return results[n - 1];
}
}
查看11道真题和解析