Skip to content

Commit 4202543

Browse files
committed
add instruction for quicksort(python)
1 parent c2687a3 commit 4202543

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Tag/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Python doesn't need to consider this.
2222
### BFS&DFS
2323
#### Depth-First Search
2424
Solution 1: DFS with queue / iterative DFS
25-
Here give an example for LC437 Path Sum
25+
Here give an example for LC437 [Path Sum](https://leetcode-cn.com/problems/path-sum-iii/)
2626
```C++ {.line-numbers}
2727
/**
2828
* Definition for a binary tree node.
@@ -172,8 +172,8 @@ H 493 [Reverse Pairs](https://leetcode-cn.com/problems/reverse-pairs/) (Solution
172172
if (nums[i]<=pivot){
173173
swap(nums[i], nums[++pos]);
174174
// maintain 4 regions
175-
// | --- | --- | ------- | - |
176-
// [l pos] i] r-1] r]
175+
// nums: [ -1- | -2- | ---3--- | - ]
176+
// ix: [l pos] i] r-1] r]
177177
// 1. l<=k<=pos, nums[k]<=pivot
178178
// 2. pos<k<=i, nums[k]>pivot
179179
// 3. i<k<=r-1, nums[k]?pivot
@@ -211,6 +211,13 @@ class Solution:
211211
if (nums[i] <= pivot):
212212
pos += 1
213213
swap(nums[i], nums[pos])
214+
# maintain 4 regions
215+
# nums: [ -1- | -2- | ---3--- | - ]
216+
# ix: [l pos] i] r-1] r]
217+
# 1. l<=k<=pos, nums[k]<=pivot
218+
# 2. pos<k<=i, nums[k]>pivot
219+
# 3. i<k<=r-1, nums[k]?pivot
220+
# 4. k==r, nums[k]==pivot(==nums[r])
214221
215222
sawp(nums[r], nums[pos+1])
216223
return nums, pos+1

0 commit comments

Comments
 (0)