mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Update source codes.
This commit is contained in:
@ -358,7 +358,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||
""" 在数组的索引 index 处插入元素 num """
|
||||
def insert(nums, num, index):
|
||||
# 把索引 index 以及之后的所有元素向后移动一位
|
||||
for i in range(len(nums) - 1, index , -1):
|
||||
for i in range(len(nums) - 1, index, -1):
|
||||
nums[i] = nums[i - 1]
|
||||
# 将 num 赋给 index 处元素
|
||||
nums[index] = num
|
||||
|
||||
Reference in New Issue
Block a user