mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-12 15:36:05 +00:00
build
This commit is contained in:
@@ -63,12 +63,12 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="insertion_sort.py"
|
||||
def insertion_sort(nums):
|
||||
def insertion_sort(nums: List[int]) -> None:
|
||||
""" 插入排序 """
|
||||
# 外循环:base = nums[1], nums[2], ..., nums[n-1]
|
||||
for i in range(1, len(nums)):
|
||||
base = nums[i]
|
||||
j = i - 1
|
||||
base: int = nums[i]
|
||||
j: int = i - 1
|
||||
# 内循环:将 base 插入到左边的正确位置
|
||||
while j >= 0 and nums[j] > base:
|
||||
nums[j + 1] = nums[j] # 1. 将 nums[j] 向右移动一位
|
||||
|
||||
Reference in New Issue
Block a user