Python Code


  • 2
    R
    class Solution(object):
        def longestPalindrome(self, s):
            """
            :type s: str
            :rtype: int
            """
            counter, sum = dict(), 0
            flag = True
            for i in s:
               counter.setdefault(i,0)
               counter[i] += 1
    
            for v in counter.values():
                if v & 1:
                    sum += v-1
                    flag = False
                else:
                    sum += v
                    
            return sum if flag else sum + 1
    

  • 0
    P

    clear and concise solution


Log in to reply
 

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