Python solution


  • 0
    R
    class Solution(object):
        def longestPalindrome(self, s):
            """
            :type s: str
            :rtype: int
            """
            dict1={}
            for each in s:
                if each in dict1:
                    dict1[each]+=1
                else:
                    dict1[each]=1
            listvalue=list(dict1.values())
            listvalue1=[x-int(x/2)*2 for x in listvalue]
            if max(listvalue1)==0:
                return sum(listvalue)
            else:
                return sum(listvalue)-sum(listvalue1)+1
    

Log in to reply
 

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