my python

  • 0
    class Solution(object):
        def longestPalindrome(self, s):
            :type s: str
            :rtype: int
            dic,res= {},0
            for i in s:
                dic[i] = dic.get(i,0)+1
            for j in dic:
                if dic[j]%2 == 0:
                    res += dic[j]
                    if dic[j] > 2:
                        res += dic[j]-1
            return res if len(s)==res else res+1

Log in to reply

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