Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-09-12 11:07:19
https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/description/
1647. Minimum Deletions to Make Character Frequencies Unique
给你一个字串,找出最少要从该字串删除几个字符才可以让所有字母的数量都不同(数量0
不算)。
Example 1:
Input: s = "aab"
Output: 0
Explanation: s is already good.
Example 2:
Input: s = "aaabbbcc"
Output: 2
Explanation: You can delete two 'b's resulting in the good string "aaabcc".
Another way it to delete one 'b' and one 'c' resulting in the good string
"aaabbc".
Example 3:
Input: s = "ceabaacb"
Output: 2
Explanation: You can delete both 'c's resulting in the good string "eabaab".
Note that we only care about characters that are still in the string at the
end (i.e. frequency of 0 is ignored).
思路:
1.先统计所有字母的数量。
2.尝试把字母加入set,如果之前已经有这个数量的话就不断的删除字母并计数,直到
没有出现过这个数量或全部字母都被删除为止。
Java Code:

Links booklink

Contact Us: admin [ a t ] ucptt.com