Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.1897. Redistribute Characters to
Browse files Browse the repository at this point in the history
Make All Strings Equal
  • Loading branch information
yanglbme committed Jul 31, 2021
1 parent 4a283e9 commit f6488e3
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class Solution:
for c in word:
counter[c] += 1
n = len(words)
for count in counter.values():
if count % n != 0:
return False
return True
return all(count % n == 0 for count in counter.values())
```

### **Java**
Expand Down Expand Up @@ -110,6 +107,47 @@ function makeEqual(words: string[]): boolean {
};
```

### **C++**

```cpp
class Solution {
public:
bool makeEqual(vector<string>& words) {
vector<int> counter(26, 0);
for (string word : words) {
for (char c : word) {
++counter[c - 'a'];
}
}
int n = words.size();
for (int count : counter) {
if (count % n != 0) return false;
}
return true;
}
};
```
### **Go**
```go
func makeEqual(words []string) bool {
counter := [26]int{}
for _, word := range words {
for _, c := range word {
counter[c-'a']++
}
}
n := len(words)
for _, count := range counter {
if count%n != 0 {
return false
}
}
return true
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ class Solution:
for c in word:
counter[c] += 1
n = len(words)
for count in counter.values():
if count % n != 0:
return False
return True
return all(count % n == 0 for count in counter.values())
```

### **Java**
Expand Down Expand Up @@ -102,6 +99,47 @@ function makeEqual(words: string[]): boolean {
};
```

### **C++**

```cpp
class Solution {
public:
bool makeEqual(vector<string>& words) {
vector<int> counter(26, 0);
for (string word : words) {
for (char c : word) {
++counter[c - 'a'];
}
}
int n = words.size();
for (int count : counter) {
if (count % n != 0) return false;
}
return true;
}
};
```
### **Go**
```go
func makeEqual(words []string) bool {
counter := [26]int{}
for _, word := range words {
for _, c := range word {
counter[c-'a']++
}
}
n := len(words)
for _, count := range counter {
if count%n != 0 {
return false
}
}
return true
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
bool makeEqual(vector<string>& words) {
vector<int> counter(26, 0);
for (string word : words) {
for (char c : word) {
++counter[c - 'a'];
}
}
int n = words.size();
for (int count : counter) {
if (count % n != 0) return false;
}
return true;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func makeEqual(words []string) bool {
counter := [26]int{}
for _, word := range words {
for _, c := range word {
counter[c-'a']++
}
}
n := len(words)
for _, count := range counter {
if count%n != 0 {
return false
}
}
return true
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ def makeEqual(self, words: List[str]) -> bool:
for c in word:
counter[c] += 1
n = len(words)
for count in counter.values():
if count % n != 0:
return False
return True
return all(count % n == 0 for count in counter.values())

0 comments on commit f6488e3

Please sign in to comment.