Longest Palindrome

Problem Id: 409 Difficulty: Easy


Intuition

Solution


class Solution:
    def longestPalindrome(self, s: str) -> int:
        length = 0
        single = False
        for c in string.ascii_letters:
            count = s.count(c)
            length += count - count % 2
            if count % 2 == 1:
                single = True
        if single:
            length += 1
        return length