Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d302a2

Browse files
Update 3.insertionSort.md
1 parent 7834c26 commit 9d302a2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

‎3.insertionSort.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ function insertionSort(arr) {
3434
}
3535
return arr;
3636
}
37-
```
37+
```
38+
39+
## 3. Python 代码实现
40+
41+
```python
42+
def insertionSort(arr):
43+
for i in range(len(arr)):
44+
preIndex = i-1
45+
current = arr[i]
46+
while preIndex >= 0 and arr[preIndex] > current:
47+
arr[preIndex+1] = arr[preIndex]
48+
preIndex-=1
49+
arr[preIndex+1] = current
50+
return arr
51+
'''

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /