diff options
author | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /min_deletions_unique_char.cpp | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip |
Diffstat (limited to 'min_deletions_unique_char.cpp')
-rw-r--r-- | min_deletions_unique_char.cpp | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/min_deletions_unique_char.cpp b/min_deletions_unique_char.cpp deleted file mode 100644 index c971b21..0000000 --- a/min_deletions_unique_char.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "leetcode.h" - -class Solution { -public: - int minDeletions(string s) { - vector<int> freq(26, 0); - int ans = 0; - for (char c : s) - freq[c - 'a']++; - sort(freq.begin(), freq.end()); - for (int i = 24; i >= 0; i--) { - if (freq[i] == 0) - break; - if (freq[i] >= freq[i + 1]) { - int prev = freq[i]; - freq[i] = max(0, freq[i + 1] - 1); - ans += prev - freq[i]; - } - } - return ans; - } -}; - -int main() { - Solution obj; - string s = "aab"; - cout << obj.minDeletions(s); -} |