18: maximum path sum I

This commit is contained in:
VicRen
2020-10-17 21:48:29 +08:00
parent 1d172fd23c
commit e8b3d67981
3 changed files with 122 additions and 0 deletions
@@ -0,0 +1,43 @@
package main
import (
"testing"
)
func TestLargestSumOfTriangle(t *testing.T) {
tt := []struct {
name string
input [][]int
want int
}{
{
"example",
[][]int{{3}, {7, 4}, {2, 4, 6}, {8, 5, 9, 3}},
23,
},
{
"example_2",
[][]int{{3}, {7, 4}},
10,
},
{
"example_3",
[][]int{{3}},
3,
},
{
"example_4",
[][]int{{3}, {7, 4}, {2, 4, 6}},
14,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got := LargestSumOfTriangle(tc.input)
if got != tc.want {
t.Errorf("LargestSumOfTriangle(%v)=%d, want %d", tc.input, got, tc.want)
}
})
}
}