3223.cpp (331B)
1 class Solution { 2 public: 3 int minimumLength(const string &s) const { 4 int count[26] = {0}; 5 int res = 0; 6 7 for (const char c : s) { 8 count[c - 'a']++; 9 } 10 11 for (int i = 0; i < 26; i++) { 12 res += (count[i] - 1) / 2; 13 } 14 15 return size(s) - 2 * res; 16 } 17 };