mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Update array.go
This commit is contained in:
@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user