C++ solution using map, with explanations - O(n) time, O(1) space - faster than 96%
\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        int res = 0;\n        unordered_map<char, int> map;\n        for (int i=0; i<s.size(
```\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        int res = 0;\n        unordered_map<char, int> map;\n        for (int i=0; i<s.size(); i++) // save in map the amount of each letter in s\n        {\n            map[s[i]]++;\n        }\n        bool flag = false;\n        for (auto x : map)\n        {\n            res += x.second - (x.second % 2); // add 2 to res for each pair of the same letter\n            if (x.second % 2) // allow one letter to be only once - for odd length palindrome\n                flag = true;\n        }\n        if (flag)\n            res++;\n        return res;\n    }\n};\n```
['C', 'C++']