Skip to content

Commit 49468bf

Browse files
authored
Update 2026-04-25-leetcode-python-general.md
1 parent fe6e021 commit 49468bf

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

_posts/2026-04-25-leetcode-python-general.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ tags:
1414
#### Array
1515
#### String
1616
1. list sort
17-
```python
17+
18+
```
1819
# in original list
1920
a = [3, 1, 2]
2021
a.sort()
@@ -30,12 +31,11 @@ print(a) # keep the same
3031
2. sort parameters
3132

3233
Using Timsort, which is a combination of insertion sort(small runs) and merge sort(merge sorted runs)
33-
3434
- time = best O(n), avg and worst O(nlogn)
3535
- space = O(n)
3636

3737

38-
```python
38+
```
3939
# descending sort
4040
a.sort(reverse=True)
4141
@@ -48,7 +48,9 @@ a.sort(key=lambda x: (x[0], -x[1]))
4848
#### Binary Search
4949

5050
1. Find the index of the first appearance (nums[index] <= target)
51-
```python
51+
52+
53+
```
5254
import bisect
5355
5456
a = [1, 2, 4, 4, 5]
@@ -57,7 +59,7 @@ print(bisect.bisect_left(a, 4)) # 2
5759

5860
2. Find the index of the first larger appearance ((nums[index] > target)
5961

60-
```python
62+
```
6163
import bisect
6264
6365
a = [1, 2, 4, 4, 5]

0 commit comments

Comments
 (0)