Skip to content

Commit f9ceb59

Browse files
authored
Create 1941-check-if-all-characters-have-equal-number-of-occurrences.js
1 parent 2790d3d commit f9ceb59

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var areOccurrencesEqual = function(s) {
6+
const n = s.length
7+
const arr = Array(26).fill(0), a = 'a'.charCodeAt(0)
8+
for(const ch of s) {
9+
arr[ch.charCodeAt(0) - a]++
10+
}
11+
const set = new Set()
12+
for(const e of arr) {
13+
if(e !== 0) set.add(e)
14+
if(set.size > 1) return false
15+
}
16+
return true
17+
};

0 commit comments

Comments
 (0)