Skip to content

Commit 99f7dff

Browse files
authored
Create 1137-n-th-tribonacci-number.js
1 parent 2f3d40f commit 99f7dff

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

1137-n-th-tribonacci-number.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const hash = {}
6+
const tribonacci = function(n) {
7+
if(n === 0) return 0
8+
if(n === 2 || n === 1) return 1
9+
if(hash[n] != null) return hash[n]
10+
let tmp = tribonacci(n - 3) + tribonacci(n - 2) + tribonacci(n - 1)
11+
return hash[n] = tmp
12+
};

0 commit comments

Comments
 (0)