mirror of
https://github.com/krahets/hello-algo.git
synced 2026-09-01 04:47:12 +00:00
build
This commit is contained in:
@@ -127,12 +127,6 @@ comments: true
|
||||
[class]{}-[func]{two_sum_brute_force}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="two_sum.zig"
|
||||
[class]{}-[func]{twoSumBruteForce}
|
||||
```
|
||||
|
||||
この方法の時間計算量は$O(n^2)$、空間計算量は$O(1)$で、大容量データでは非常に時間がかかる可能性があります。
|
||||
|
||||
## 10.4.2 ハッシュ探索:空間を時間と交換
|
||||
@@ -270,12 +264,6 @@ comments: true
|
||||
[class]{}-[func]{two_sum_hash_table}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="two_sum.zig"
|
||||
[class]{}-[func]{twoSumHashTable}
|
||||
```
|
||||
|
||||
この方法は、ハッシュ探索を使用することで時間計算量を$O(n^2)$から$O(n)$に削減し、実行時効率を大幅に向上させます。
|
||||
|
||||
追加のハッシュテーブルを維持する必要があるため、空間計算量は$O(n)$です。**それにもかかわらず、この方法は全体的により均衡のとれた時空間効率を持ち、この問題の最適解となります**。
|
||||
|
||||
Reference in New Issue
Block a user