> 其他 >
Java - 斐波那契数列 - recursive
Write recursive Java code to compute terms of the Fibonacci sequence.Use this to compute the 5th,10th,40th,60th and 90th terms.我用基本的recursive写了一下,可是到40项以后就算不出来了.如果仅用加法算最近的两项(释放其他内存),又不算是recursive,求一种既是recursive又可以用普通的单核电脑算出来的java code...
这种recursive:
public static long fib(long n) {
if (n
人气:425 ℃ 时间:2020-06-28 10:28:33
解答
用散列表加了个缓存,可以算到long最大值存不下了吧
import java.util.Hashtable;
public class Test {
public static long fib(int n,Hashtable t) {
if (n
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版