【leetcode❤python】409. Longest Palindrome
#-*- coding: UTF-8 -*-
from collections import Counter
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: int
"""
lopa=0
lopa1=0
slist=list(s)
result=Counter(s)
maxOdd=1
maxKey=None
oddDic={}
for k,v in result.iteritems():
if v%2==0:lopa+=v
else:
oddDic.setdefault(k,v)
if v>=maxOdd:maxOdd=v;maxKey=k
if maxKey!=None:lopa+=maxOdd;oddDic.pop(maxKey)
if oddDic!=None:
for v in oddDic.itervalues():
lopa+=v/2*2
return lopa
sol=Solution()
print sol.longestPalindrome('ccc')