leetcode在力扣 App 中打开
调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

如果字符串 s不存在 两个不同字符 频次 相同的情况,就称 s优质字符串

给你一个字符串 s,返回使 s 成为 优质字符串 需要删除的 最小 字符数。

字符串中字符的 频次 是该字符在字符串中的出现次数。例如,在字符串 "aab" 中,'a' 的频次是 2,而 'b' 的频次是 1

 

示例 1:

输入:s = "aab"
输出:0
解释:s 已经是优质字符串。

示例 2:

输入:s = "aaabbbcc"
输出:2
解释:可以删除两个 'b' , 得到优质字符串 "aaabcc" 。
另一种方式是删除一个 'b' 和一个 'c' ,得到优质字符串 "aaabbc" 。

示例 3:

输入:s = "ceabaacb"
输出:2
解释:可以删除两个 'c' 得到优质字符串 "eabaab" 。
注意,只需要关注结果字符串中仍然存在的字符。(即,频次为 0 的字符会忽略不计。)

 

提示:

  • 1 <= s.length <= 105
  • s 仅含小写英文字母
通过次数
16.4K
提交次数
29.9K
通过率
55.0%


相关企业

提示 1
As we can only delete characters, if we have multiple characters having the same frequency, we must decrease all the frequencies of them, except one.

提示 2
Sort the alphabet characters by their frequencies non-increasingly.

提示 3
Iterate on the alphabet characters, keep decreasing the frequency of the current character until it reaches a value that has not appeared before.


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
s =
"aab"
Source