Description
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.
Code
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: int
"""
from collections import Counter
c = Counter(s)
ans = 0
flag = 0
for key in c:
if c[key] & 1:
flag = 1
ans += c[key] / 2
ans <<= 1
ans += flag
return ans