public class Solution {
//动态规划的思想,这个星期好好学动态规划,不过还是要把搜索基础打牢,再剪枝
private int[] fib = new int[40];
public Solution() {
fib[1] = 1;
fib[2] = 2;
for (int i = 2; i < fib.length; i++)
fib[i] = fib[i - 1] + fib[i - 2];
}
public int Fibonacci(int n) {
return fib[n];
}
}
剑指offer10斐波那契数列
最新推荐文章于 2022-03-22 16:47:49 发布