Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add a description of the solution to lc problem: No.0075 #683

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions solution/0000-0099/0075.Sort Colors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@

<!-- 这里可写通用的实现逻辑 -->

有两种方式

- 排序
- 题目本质还是排序,可用 `sort()` 一键解锁。
- 双指针
- 数组元素只存在 `0`、`1` 和 `2` 三种,因此将 `0` 移动至数组头部,`2` 移动至数组尾部,排序便完成了。
- 安排两个变量,分别指向数组头部与尾部。
- 遍历数组,分三种情况:
- `0`:与头指针数值交换,并向前一步,遍历指针向前。
- `2`:与尾指针数值交换,并向后一步。**遍历指针不变**(还需要处理交换上来的数值)。
- `1`:遍历指针向前。

<!-- tabs:start -->

### **Python3**
Expand Down