Python beat 98.25%


  • 0
    L
        def longestPalindrome(self, s):
            """
            :type s: str
            :rtype: int
            """
            countDict = {}
            for c in s:
                if c in countDict:
                    countDict[c] = countDict[c] + 1
                else:
                    countDict[c] = 1
            
            sum = 0;
            idx = False;
            for c in countDict:
                count = countDict[c]
                if count % 2 == 1:
                    idx = True
                sum = sum + (count // 2) * 2
            if idx:
                return sum + 1
            else:
                return sum```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.