File tree Expand file tree Collapse file tree 5 files changed +116
-12
lines changed
solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal Expand file tree Collapse file tree 5 files changed +116
-12
lines changed Original file line number Diff line number Diff line change @@ -59,10 +59,7 @@ class Solution:
5959 for c in word:
6060 counter[c] += 1
6161 n = len (words)
62- for count in counter.values():
63- if count % n != 0 :
64- return False
65- return True
62+ return all (count % n == 0 for count in counter.values())
6663```
6764
6865### ** Java**
@@ -110,6 +107,47 @@ function makeEqual(words: string[]): boolean {
110107};
111108```
112109
110+ ### ** C++**
111+
112+ ``` cpp
113+ class Solution {
114+ public:
115+ bool makeEqual(vector<string >& words) {
116+ vector<int > counter(26, 0);
117+ for (string word : words) {
118+ for (char c : word) {
119+ ++counter[ c - 'a'] ;
120+ }
121+ }
122+ int n = words.size();
123+ for (int count : counter) {
124+ if (count % n != 0) return false;
125+ }
126+ return true;
127+ }
128+ };
129+ ```
130+
131+ ### **Go**
132+
133+ ```go
134+ func makeEqual(words []string) bool {
135+ counter := [26]int{}
136+ for _, word := range words {
137+ for _, c := range word {
138+ counter[c-'a']++
139+ }
140+ }
141+ n := len(words)
142+ for _, count := range counter {
143+ if count%n != 0 {
144+ return false
145+ }
146+ }
147+ return true
148+ }
149+ ```
150+
113151### ** ...**
114152
115153```
Original file line number Diff line number Diff line change @@ -53,10 +53,7 @@ class Solution:
5353 for c in word:
5454 counter[c] += 1
5555 n = len (words)
56- for count in counter.values():
57- if count % n != 0 :
58- return False
59- return True
56+ return all (count % n == 0 for count in counter.values())
6057```
6158
6259### ** Java**
@@ -102,6 +99,47 @@ function makeEqual(words: string[]): boolean {
10299};
103100```
104101
102+ ### ** C++**
103+
104+ ``` cpp
105+ class Solution {
106+ public:
107+ bool makeEqual(vector<string >& words) {
108+ vector<int > counter(26, 0);
109+ for (string word : words) {
110+ for (char c : word) {
111+ ++counter[ c - 'a'] ;
112+ }
113+ }
114+ int n = words.size();
115+ for (int count : counter) {
116+ if (count % n != 0) return false;
117+ }
118+ return true;
119+ }
120+ };
121+ ```
122+
123+ ### **Go**
124+
125+ ```go
126+ func makeEqual(words []string) bool {
127+ counter := [26]int{}
128+ for _, word := range words {
129+ for _, c := range word {
130+ counter[c-'a']++
131+ }
132+ }
133+ n := len(words)
134+ for _, count := range counter {
135+ if count%n != 0 {
136+ return false
137+ }
138+ }
139+ return true
140+ }
141+ ```
142+
105143### ** ...**
106144
107145```
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ bool makeEqual (vector<string>& words) {
4+ vector<int > counter (26 , 0 );
5+ for (string word : words) {
6+ for (char c : word) {
7+ ++counter[c - ' a' ];
8+ }
9+ }
10+ int n = words.size ();
11+ for (int count : counter) {
12+ if (count % n != 0 ) return false ;
13+ }
14+ return true ;
15+ }
16+ };
Original file line number Diff line number Diff line change 1+ func makeEqual (words []string ) bool {
2+ counter := [26 ]int {}
3+ for _ , word := range words {
4+ for _ , c := range word {
5+ counter [c - 'a' ]++
6+ }
7+ }
8+ n := len (words )
9+ for _ , count := range counter {
10+ if count % n != 0 {
11+ return false
12+ }
13+ }
14+ return true
15+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,4 @@ def makeEqual(self, words: List[str]) -> bool:
55 for c in word :
66 counter [c ] += 1
77 n = len (words )
8- for count in counter .values ():
9- if count % n != 0 :
10- return False
11- return True
8+ return all (count % n == 0 for count in counter .values ())
You can’t perform that action at this time.
0 commit comments