-
-
Notifications
You must be signed in to change notification settings - Fork 47.8k
Commit 37b34c2
sowndappan5MaximSmolskiypre-commit-ci[bot]
authoredperf(strings): optimize anagram signature using frequency counts (#12927)
* fix(strings): use frequency-based signature for anagrams
Replaced the sorting-based signature implementation with a frequency-based
approach using `collections.Counter`. This ensures that the signature
represents both characters and their counts, preventing collisions and
better grouping of true anagrams.
Examples:
- "test" → "e1s1t2"
- "finaltest" → "a1e1f1i1l1n1s1t2"
- "this is a test" → " 3a1e1h1i2s3t3"
Also updated the anagram lookup to use the new frequency-based signatures, making results more accurate and avoiding false positives.
* Refactor anagram function return type to list[str]
* Update anagrams.py
* Update anagrams.py
* Update anagrams.py
* Update anagrams.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent d16cac6 commit 37b34c2
1 file changed
+14
-7
lines changedLines changed: 14 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
9 | - | ||
9 | + | ||
10 | + | ||
11 | + | ||
10 | 12 |
| |
11 | - | ||
13 | + | ||
12 | 14 |
| |
13 | - | ||
15 | + | ||
14 | 16 |
| |
15 | - | ||
17 | + | ||
16 | 18 |
| |
17 | - | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | + | ||
18 | 23 |
| |
19 | 24 |
| |
20 | 25 |
| |
21 | - | ||
26 | + | ||
27 | + | ||
28 | + | ||
22 | 29 |
| |
23 | 30 |
| |
24 | 31 |
| |
| |||
40 | 47 |
| |
41 | 48 |
| |
42 | 49 |
| |
43 | - | ||
50 | + | ||
44 | 51 |
|
0 commit comments