Python Solution with Explanation
Assume character frequency = K\n\n1. If all the characters appears even times, then we just add up all the frequencies (K) and returns the result.\n\n\tEx. aabb
Assume character frequency = K\n\n1. If all the characters appears even times, then we just add up all the frequencies (K) and returns the result.\n\n\tEx. aabb -> abba\n\n2. If one or more characters appears odd times, we noted down that an odd frequency character had appeared, and just increment result `K-1` (since odd frequency reduced by 1 is even frequency, meaning we can use an odd frequency word even times). \n In the end, add 1 back to the overall sum, since in parlindrome, we can have one and only one odd frequency character (highest out of all odd frequency characters) and make the string longest parlindrome.\n\n\tEx. aabbcccppppp-> abppcpcppba\n\n\tHere `c` appears 3 times, `p` appears 5 times, we know we should always use the highest of all odd frequency character, and have the rest of the odd frequency words appear even times. In the example we ended up using `p` 5 times, but `c` 2 times, and it\'s the longnest parlindrome.\n\n```\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        from collections import Counter\n        \n        freq = Counter(s)\n        \n        odd = False\n        res = 0\n        \n        for k,v in freq.items():\n            if v % 2 == 0:\n                res += v\n            else:\n                res += v-1\n                odd = True\n        \n        if odd:\n            res += 1\n            \n        return res\n```
['Python']