1647. Make Character Frequencies Unique
Question
A string
s
is called good if there are no two different characters ins
that have the same frequency.Given a string
s
, return* the minimum number of characters you need to delete to makes
good.*The frequency of a character in a string is the number of times it appears in the string. For example, in the string
"aab"
, the frequency of'a'
is2
, while the frequency of'b'
is1
.
Solution
数组统计+哈希表
用数组统计记录每个字符出现的数量。
count记录需要减少的字符数量。
遍历统计数组,如果哈希表中已经记录,则将数组统计减少,直到归零。
每减少一次则为count加一。
如果哈希表中未记录,则将当前数字添加到哈希表中。
Code
1 | class Solution { |
1647. Make Character Frequencies Unique
https://xuanhe95.github.io/2022/06/28/1647-Make-Character-Frequencies-Unique/