
思路:
计算字符串中每个字符串出现的频率,如果出现的次数为偶数,则全部用来做回文串,如果出现的次数为奇数且大于1,取偶数个作为回文串,如果出现1次,那么作为最中间的值。
重点:collections.Counter(),用以计算每个字符串中字符出现的频率
class Solution:
    def longestPalindrome(self, s: str) -> int:
        ans=0
        count=collections.Counter(s)
        for value in count.values():
            ans+=value//2*2
            if ans%2==0 and value%2==1:
                ans+=1
        return ans










