修复代码bug--> exercises/chapter_7/remove_slice.go (#433)

* 修复代码bug, 切片取值错误导致结果偏差,丢失最后一个元素,优化创建切片的容量,避免每次自动扩容1个大小

* 使用切片完成操作
This commit is contained in:
Allen.Guo
2018-03-05 16:54:44 +08:00
committed by jc
parent f559f17fcf
commit 695188fe0d
2 changed files with 17 additions and 14 deletions

View File

@@ -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
}