(python) long and easy to understand


  • 0

    class Solution(object):
    def longestPalindrome(self, s):
    """
    :type s: str
    :rtype: int
    """
    num=0
    d = {}
    for c in s:
    d[c]=d.get(c,0)+1
    tip=0 # middle
    for x in d.keys():
    if d[x]%2==0:
    num+=d[x]
    else:
    num=num+d[x]-1
    tip=1
    return tip+num


  • 0
    This post is deleted!

Log in to reply
 

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