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/1800-1899/1897.Redistribute Characters to Make All Strings Equal/README_EN.md
+54-33
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,13 @@ All the strings are now equal to "abc", so return <code>true</code>.
60
60
61
61
<!-- solution:start -->
62
62
63
-
### Solution 1
63
+
### Solution 1: Counting
64
+
65
+
According to the problem description, as long as the occurrence count of each character can be divided by the length of the string array, it is possible to redistribute the characters to make all strings equal.
66
+
67
+
Therefore, we use a hash table or an integer array of length $26$ $\textit{cnt}$ to count the occurrences of each character. Finally, we check if the occurrence count of each character can be divided by the length of the string array.
68
+
69
+
The time complexity is $O(L)$, and the space complexity is $O(|\Sigma|)$. Here, $L$ is the total length of all strings in the array $\textit{words}$, and $\Sigma$ is the character set, which is the set of lowercase letters, so $|\Sigma|=26$.
64
70
65
71
<!-- tabs:start -->
66
72
@@ -69,28 +75,28 @@ All the strings are now equal to "abc", so return <code>true</code>.
0 commit comments