Update the array (Go code).

This commit is contained in:
Yudong Jin
2023-01-02 19:03:36 +08:00
parent 1f1c58519d
commit 5cb62fd458
2 changed files with 4 additions and 5 deletions

View File

@@ -27,8 +27,8 @@ func extend(nums []int, enlarge int) []int {
// 初始化一个扩展长度后的数组
res := make([]int, len(nums)+enlarge)
// 将原数组中的所有元素复制到新数组
for i := 0; i < len(nums); i++ {
res[i] = nums[i]
for i, num := range nums {
res[i] = num
}
// 返回扩展后的新数组
return res