-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
v_yongztan
committed
Nov 5, 2020
1 parent
0e83245
commit 9a403ec
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 剑指 Offer 10- I. 斐波那契数列. | ||
// https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/ | ||
// start 21:45 end | ||
|
||
/** | ||
* @param {number} n | ||
* @return {number} | ||
*/ | ||
var fib = function (n) { | ||
let res = [0, 1] | ||
|
||
function f(n) { | ||
if (typeof res[n] !== 'undefined') { | ||
return res[n] | ||
} | ||
// console.log(`res[${n}] = f(${n - 1}) + f(${n - 2})`) | ||
res[n] = (f(n - 1) + f(n - 2)) % 1000000007 | ||
// console.log(res) | ||
return res[n] | ||
} | ||
return f(n) | ||
}; | ||
|
||
console.log(fib(81)) |