```
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: int
"""
counter, sum = dict(), 0
flag = True
for i in s:
counter.setdefault(i,0)
counter[i] += 1
for v in counter.values():
if v & 1:
sum += v-1
flag = False
else:
sum += v
return sum if flag else sum + 1
```