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