val list = listOf(
listOf(1, 2, 5),
listOf(1, 2, 6),
listOf(1, 3, 1),
listOf(1, 3, 5),
listOf(1, 3, 7))
val mutableMap = mutableMapOf<Int, Int>()
list.forEach { intList ->
if (intList.count() > 2) {
if (mutableMap[intList[1]] == null) {
mutableMap[intList[1]] = intList[2]
} else {
mutableMap[intList[1]] = mutableMap[intList[1]]!! + intList[2]
}
}
}
println(mutableMap) // output {2=11, 3=13} 2:加總11, 3:加總13
哪裡有寫錯或是可以更優化的地方歡迎指正