Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
    This is case sensitive, for example "Aa" is not considered a palindrome here.
    Note:
    Assume the length of given string will not exceed 1,010.
    Example:
    Input:
    “abccccdd”

    Output:
    7

    Explanation:
    One longest palindrome that can be built is “dccaccd”, whose length is 7.

    Runtime: 4 ms, faster than 92.68% of C++ online submissions for Longest Palindrome.

    1. class Solution {
    2. public:
    3. int longestPalindrome(string s) {
    4. int size = s.size();
    5. if (s.size() < 1) {
    6. return 0;
    7. }
    8. unordered_map<int, int> map;
    9. int sum = 1;
    10. for (char ch : s) {
    11. map[ch]++;
    12. if (map[ch] == 2) {
    13. sum += 2;
    14. map[ch] = 0;
    15. }
    16. }
    17. return sum > size ? size : sum;
    18. }
    19. };