Commit 1bd6670
Optimize remove_duplicates from O(n²) to O(n) time complexity
Use a set for O(1) membership checks instead of checking membership in a list which is O(n). This reduces the overall time complexity from O(n²) to O(n).
Added documentation for time and space complexity.
Co-Authored-By: Keon <kwk236@gmail.com>1 parent 5b63e90 commit 1bd6670
1 file changed
+7
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | | - | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | | - | |
| 23 | + | |
0 commit comments