Dar*_*tle 11
你的代码不是Go代码(它将作为Ruby传递),而且没有明确的尝试来实际解决问题,这可能是你得到一些downvotes而没有答案的原因.
inputabinterface{}
type ab struct {
a int
b []int
}
input[][]abababinputoutput
package main
import "fmt"
func main() {
input := []map[int][]int{
{
1: []int{1, 2},
2: []int{1, 2},
3: []int{1, 2},
},
{
1: []int{3, 4},
2: []int{3, 4},
3: []int{3, 4},
4: []int{3, 4},
},
{
1: []int{5, 6},
2: []int{5, 6},
3: []int{5, 6},
4: []int{5, 6},
5: []int{5, 6},
},
}
output := make(map[int][]int)
for _, m := range input {
for k, v := range m {
output[k] = append(output[k], v...)
}
}
fmt.Println(output)
}
这会产生输出:
map[1:[1 2 3 4 5 6] 2:[1 2 3 4 5 6] 3:[1 2 3 4 5 6] 4:[3 4 5 6] 5:[5 6]]
output