We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 循环的方式 var fib = function(n) { if(n==0) return 0 if(n==1) return 1 // loop let fn1 = 0 let fn2 = 1 let fn3 for(let i=2; i<=n; i++) { fn3 = (fn1 + fn2) % 1000000007 fn1 = fn2 fn2 = fn3 } return fn2 };
正常的傻递归时间复杂度通常是O(2^n),因为有很多重复计算的结点,因此可以通过记忆化优化,通过另外的数组存在已经算过的结点,如果发现计算了直接使用。大多数递归都可以都过自顶向上的循环来改写。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
leetcdoe剑指 Offer 10- I. 斐波那契数列
题目链接
思路
总结
正常的傻递归时间复杂度通常是O(2^n),因为有很多重复计算的结点,因此可以通过记忆化优化,通过另外的数组存在已经算过的结点,如果发现计算了直接使用。大多数递归都可以都过自顶向上的循环来改写。
The text was updated successfully, but these errors were encountered: