mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-01 20:12:07 +08:00
Fix my list.
This commit is contained in:
@ -55,11 +55,14 @@ class MyList:
|
||||
""" 删除元素 """
|
||||
def remove(self, index):
|
||||
assert index < self.__size, "索引越界"
|
||||
num = self.nums[index]
|
||||
# 索引 i 之后的元素都向前移动一位
|
||||
for j in range(index, self.__size - 1):
|
||||
self.__nums[j] = self.__nums[j + 1]
|
||||
# 更新元素数量
|
||||
self.__size -= 1
|
||||
# 返回被删除元素
|
||||
return num
|
||||
|
||||
""" 列表扩容 """
|
||||
def extend_capacity(self):
|
||||
|
||||
Reference in New Issue
Block a user