-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
26 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
{{#include assets/rotate.rs:7:50}} | ||
``` | ||
|
||
## 方法2: 使用数组反转 | ||
## 方法2: 三次反转法 | ||
|
||
操作过程如下: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
# | ||
# 旋转数组 Rotate Array | ||
|
||
[问题描述](https://leetcode.com/problems/rotate-array/) | ||
|
||
## 三次反转法 | ||
|
||
操作过程如下: | ||
|
||
1. 将 `arr[k..n]` 进行反转 | ||
2. 将 `arr[0..k]` 进行反转 | ||
3. 将 `arr[..]` 进行反转 | ||
|
||
这个方法是在原地操作的, 其时间复杂度是 `O(n)`, 空间复杂度是 `O(1)`. | ||
|
||
```rust | ||
{{#include src/main.rs:31:49}} | ||
``` | ||
|
||
## 参考 | ||
|
||
- [旋转数组](../../array/rotate.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters