Longest Palindrome

偶数全拿,奇数减1再拿,最后判断有没有奇数,没有就是result,有就是result + 1

class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: int
        """
        counter = collections.Counter(s)
        result = 0
        odd = False
        for key, value in counter.items():
            if value % 2 == 0:
                result += value
            else:
                odd = True
                result += (value - 1)

        return result + 1 if odd else result

results matching ""

    No results matching ""