, , , , , . . (9, 3, 5), (8, 4, 7), (6, 1, 8), , , 5 4. , , 7 3, 1. , , , .
, . , , . , , :
, List<List<Integer>>
.
int minSum(int index, int previous, List<List<Integer>> inputs) {
if (index >= inputs.size())
return 0;
else
return IntStream.range(0, 3)
.filter(n -> n != previousIndex)
.map(n -> minSum(index + 1, n, inputs)).min();
}
, Java 8 .
, . , , , .
, (1, 8, 5), (2, 3, 6), (4, 9, 2). 1 + 3 + 4 7. , , - 8 . , , , (.. 7), , , .
, . , , .