As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center获取指导。




已关闭8年。





已知用于计算斐波那契数列第n个项的最快Java算法是什么?

我找到了these algorithms。我猜想迭代算法应该比递归和解析算法更快。

最佳答案

预先计算所有斐波那契数,直到n足够大,然后生成一个源代码段,该源代码段定义一个数字数组,其类型可以容纳这些数字。

然后,您可以只检索数组中索引n中的值。这是O(1)。不会比这快得多。

08-04 12:58