func MergeSliceWithStep[T any](l1 []T, l2 []T, step int) []T { merged := make([]T, len(l1)+len(l2)) i, j := 0, 0

for i < len(l1) && j < len(l2) {
    for k := 0; k < step && i < len(l1); k++ {
        merged[i+j] = l1[i]
        i++
    }
    merged[i+j] = l2[j]
    j++
}

for i < len(l1) {
    merged[i+j] = l1[i]
    i++
}

for j < len(l2) {
    merged[i+j] = l2[j]
    j++
}

return merged

}

MergeSliceWithStep merge l2 to l1 with step For every step l1 elements one l2 element is inserted and the rest is appended directly tofunc MergeSliceWithStepT anyl1 T l2 T step int T

原文地址: https://www.cveoy.top/t/topic/hRbr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录