python code use set() and count()~


  • 0

    class Solution(object):
    def longestPalindrome(self, s):
    """
    :type s: str
    :rtype: int
    """
    result=0
    odd_count=0
    for zimu in set(s):
    if s.count(zimu)%2==0:
    result+=s.count(zimu)
    if s.count(zimu)%2!=0:
    result+=s.count(zimu)-1
    odd_count+=1
    return result+1 if odd_count>0 else result


Log in to reply
 

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