Skip to content

Commit

Permalink
剑指 Offer 10- I. 斐波那契数列.
Browse files Browse the repository at this point in the history
  • Loading branch information
v_yongztan committed Nov 5, 2020
1 parent 0e83245 commit 9a403ec
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/leetcode_1_fib.js
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))

0 comments on commit 9a403ec

Please sign in to comment.