mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
修复代码bug--> exercises/chapter_7/remove_slice.go (#433)
* 修复代码bug, 切片取值错误导致结果偏差,丢失最后一个元素,优化创建切片的容量,避免每次自动扩容1个大小 * 使用切片完成操作
This commit is contained in:
@@ -12,8 +12,8 @@ func main() {
|
||||
}
|
||||
|
||||
func RemoveStringSlice(slice []string, start, end int) []string {
|
||||
result := make([]string, len(slice)-(end-start))
|
||||
result := make([]string, len(slice)-(end-start)-1)
|
||||
at := copy(result, slice[:start])
|
||||
copy(result[at:], slice[end:])
|
||||
copy(result[at:], slice[end+1:])
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user