Skip to content

Commit e59f93c

Browse files
committed
add leetcode 1137
1 parent 3d3266e commit e59f93c

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package leetcode
2+
3+
var cache = []int{0, 1, 1}
4+
5+
func tribonacci(n int) int {
6+
if n < len(cache) {
7+
return cache[n]
8+
}
9+
ret := tribonacci(n-1) + tribonacci(n-2) + tribonacci(n-3)
10+
cache = append(cache, ret)
11+
return ret
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package leetcode
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestTribonacci(t *testing.T) {
10+
assert.Equal(t, 149, tribonacci(10))
11+
assert.Equal(t, 66012, tribonacci(20))
12+
assert.Equal(t, 2082876103, tribonacci(37))
13+
}

0 commit comments

Comments
 (0)