-
发表于 2025.04.05
-
挺简单的题目,按题目的操作,字符串中所出现的每个字母最终都会减少到
1
个,所以我们只需要统计字符串中不同字母的数量即可。class Solution { public: int minimizedStringLength(string s) { vector<int> cnt_map(26, 0); for (const auto& ch : s) { cnt_map[ch - 'a']++; } int res = 0; for (int i = 0; i < 26; ++i) res += cnt_map[i] > 0; return res; } };
- LC 题目链接
-