409. Longest Palindrome

409. Longest Palindrome

from collections import Counter

class Solution:
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: int
        """
        counter = Counter(s)
        
        r = 0
        for c in counter:
            r += counter[c] // 2 * 2
            if r % 2 == 0 and counter[c] % 2 == 1:
                r += 1
        return r