diff --git a/codes/go/chapter_array_and_linkedlist/array.go b/codes/go/chapter_array_and_linkedlist/array.go index 26c056763..eb21143fe 100644 --- a/codes/go/chapter_array_and_linkedlist/array.go +++ b/codes/go/chapter_array_and_linkedlist/array.go @@ -49,11 +49,7 @@ func insert(nums []int, num int, index int) { /* 删除索引 index 处元素 */ func remove(nums []int, index int) { // 把索引 index 之后的所有元素向前移动一位 - for i := index; i < len(nums); i++ { - if i+1 >= len(nums) { - nums[len(nums)-1] = 0 - break - } + for i := index; i < len(nums) - 1; i++ { nums[i] = nums[i+1] } }