https://leetcode.com/problems/longest-palindrome/
Source
int longestPalindrome(string s) {
unordered_map<char, int> hashMap;
for (char c : s) {
hashMap[c]++;
}
int oneside = 0;
int addOne = 0;
for (auto it=std::begin(hashMap); std::end(hashMap)!=it; ++it) {
const char c = it->first;
const int num = hashMap[c];
const int half = static_cast<int>(num/2);
if (half > 0) oneside += half;
if (num%2 > 0) addOne = 1;
}
return (2*oneside + addOne);
}