/**
* 斐波那契数列(答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1)
* @Description
*/
public class Test08_1 {
public int fib(int n) {
if(n == 0 || n == 1){
return n;
}
long[] dp = new long[n+1];
dp[0] = 0;
dp[1] = 1;
for(int i = 2;i <= n;i++){
dp[i] = dp[i - 1] + dp[i - 2];
dp[i]=dp[i]% 1000000007;
}
return (int)dp[n];
}
public static void main(String[] args) {
System.out.println(new Test08_1().fib(66));
}
}
剑指Offer-07-斐波那契数列
最新推荐文章于 2022-11-30 15:44:18 发布