mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 03:30:30 +08:00
Release Rust code to documents. (#656)
This commit is contained in:
@@ -133,6 +133,14 @@
|
||||
[class]{}-[func]{permutationsI}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="permutations_i.rs"
|
||||
[class]{}-[func]{backtrack}
|
||||
|
||||
[class]{}-[func]{permutations_i}
|
||||
```
|
||||
|
||||
## 考虑相等元素的情况
|
||||
|
||||
!!! question
|
||||
@@ -249,6 +257,14 @@
|
||||
[class]{}-[func]{permutationsII}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="permutations_ii.rs"
|
||||
[class]{}-[func]{backtrack}
|
||||
|
||||
[class]{}-[func]{permutations_ii}
|
||||
```
|
||||
|
||||
假设元素两两之间互不相同,则 $n$ 个元素共有 $n!$ 种排列(阶乘);在记录结果时,需要复制长度为 $n$ 的列表,使用 $O(n)$ 时间。因此,**时间复杂度为 $O(n!n)$** 。
|
||||
|
||||
最大递归深度为 $n$ ,使用 $O(n)$ 栈帧空间。`selected` 使用 $O(n)$ 空间。同一时刻最多共有 $n$ 个 `duplicated` ,使用 $O(n^2)$ 空间。**因此空间复杂度为 $O(n^2)$** 。
|
||||
|
||||
Reference in New Issue
Block a user