forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.1897. Redistribute Characters to
Make All Strings Equal
- Loading branch information
Showing
5 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
solution/1800-1899/1897.Redistribute Characters to Make All Strings Equal/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters