Skip to content

Commit c9fc1bc

Browse files
authored
Create 1647-minimum-deletions-to-make-character-frequencies-unique.kt
1 parent 53e79c9 commit c9fc1bc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
fun minDeletions(s: String): Int {
3+
val count = HashMap<Char, Int>().apply {
4+
for (c in s)
5+
this[c] = getOrDefault(c, 0) + 1
6+
}
7+
8+
val usedFreq = HashSet<Int>()
9+
10+
var res = 0
11+
for ((char, freq) in count) {
12+
var freq = freq
13+
while (freq > 0 && freq in usedFreq) {
14+
freq--
15+
res++
16+
}
17+
usedFreq.add(freq)
18+
}
19+
20+
return res
21+
}
22+
}

0 commit comments

Comments
 (0)