```
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: int
"""
d = {}
for c in s: # count for each letter, O(n)
d[c] = d.get(c, 0) + 1
# subtract the "number of odd values minus 1" or zero from the string length, O(n)
return len(s) - max(len(tuple(v for v in d.values() if v % 2)) - 1, 0)
```