Strings


Strings

Longest Palindrome

class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: int
        """


        pairs = set()
        counter = 0
        for c in s:
            if c not in pairs:
                pairs.add(c)
            elif c in pairs:
                pairs.remove(c)
                counter += 2
        if pairs:
            counter += 1

        # a string that can't be a palindrome will just return 0
        return counter