You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2700-2799/2744.Find Maximum Number of String Pairs/README_EN.md
+23-25
Original file line number
Diff line number
Diff line change
@@ -60,13 +60,13 @@ It can be proven that 1 is the maximum number of pairs that can be formed.
60
60
61
61
### Solution 1: Hash Table
62
62
63
-
We can use a hash table $cnt$ to store the number of occurrences of each string's reversed string in the array $words$.
63
+
We can use a hash table $cnt$ to store the number of occurrences of each reversed string in the array $words$.
64
64
65
-
Traverse the array $words$, for each string $w$, we directly add the value of $cnt[w]$ to the answer, then increase the occurrence count of $w$'s reversed string by $1$.
65
+
We iterate through the array $words$. For each string $w$, we add the number of occurrences of its reversed string to the answer, then increment the count of $w$ by $1$.
66
66
67
-
After the traversal ends, we can get the maximum number of matches.
67
+
Finally, we return the answer.
68
68
69
-
The time complexity is $O(L)$, and the space complexity is $O(L)$, where $L$ is the sum of the lengths of the strings in the array $words$.
69
+
The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array $words$.
0 commit comments