mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
19 lines
412 B
Go
Executable File
19 lines
412 B
Go
Executable File
// remove_slice.go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func main() {
|
|
s := []string{"M", "N", "O", "P", "Q", "R"}
|
|
res := RemoveStringSlice(s, 2, 4)
|
|
fmt.Println(res) // [M N Q R]
|
|
}
|
|
|
|
func RemoveStringSlice(slice []string, start, end int) []string {
|
|
result := make([]string, len(slice) - (end - start))
|
|
at := copy(result, slice[:start])
|
|
copy(result[at:], slice[end:])
|
|
return result
|
|
} |