请实现以下函数 MergeSliceWithStep merge l2 to l1 with step and the balance append to l such as 1 l1=111 l2=222 step=1 output=121212 2 l1=111 l2=2 step=1 output=1211 3 l1=11 l2=222 step=1 output=12122func
func MergeSliceWithStep[T any](l1 []T, l2 []T, step int) []T { var output []T i := 0 for i < len(l1) && i < len(l2) { output = append(output, l1[i]) output = append(output, l2[i]) i += step } for i < len(l1) { output = append(output, l1[i]) i += step } for i < len(l2) { output = append(output, l2[i]) i += step } return output }
原文地址: https://www.cveoy.top/t/topic/hQ96 著作权归作者所有。请勿转载和采集!