-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1941.check-if-all-characters-have-equal-number-of-occurrences.go
More file actions
70 lines (67 loc) · 1.35 KB
/
1941.check-if-all-characters-have-equal-number-of-occurrences.go
File metadata and controls
70 lines (67 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* @lc app=leetcode id=1941 lang=golang
*
* [1941] Check if All Characters Have Equal Number of Occurrences
*
* https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/description/
*
* algorithms
* Easy (76.77%)
* Likes: 277
* Dislikes: 9
* Total Accepted: 29.1K
* Total Submissions: 37.8K
* Testcase Example: '"abacbc"'
*
* Given a string s, return true if s is a good string, or false otherwise.
*
* A string s is good if all the characters that appear in s have the same
* number of occurrences (i.e., the same frequency).
*
*
* Example 1:
*
*
* Input: s = "abacbc"
* Output: true
* Explanation: The characters that appear in s are 'a', 'b', and 'c'. All
* characters occur 2 times in s.
*
*
* Example 2:
*
*
* Input: s = "aaabb"
* Output: false
* Explanation: The characters that appear in s are 'a' and 'b'.
* 'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of
* times.
*
*
*
* Constraints:
*
*
* 1 <= s.length <= 1000
* s consists of lowercase English letters.
*
*
*/
// @lc code=start
func areOccurrencesEqual(s string) bool {
hashMap := make(map[rune]int)
for _, v := range s {
hashMap[v] = hashMap[v] + 1
}
count := -1
for _, v := range hashMap {
if count == -1 {
count = v
}
if count != v {
return false
}
}
return true
}
// @lc code=end