Skip to content

Commit 561d7ae

Browse files
committed
Solved 1897 - Redistribute Characters to Make All Strings Equal
1 parent cf9353f commit 561d7ae

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function makeEqual(words: string[]): boolean {
2+
const charMap = new Array(26).fill(0);
3+
4+
if (words.length === 1) return true;
5+
6+
for (const word of words)
7+
for (const letter of word)
8+
charMap[letter.charCodeAt(0) - "a".charCodeAt(0)]++;
9+
10+
for (const x of charMap) if (x % words.length !== 0) return false;
11+
12+
return true;
13+
}

0 commit comments

Comments
 (0)