class Solution:
def longestPalindrome(self, s):
"""
:type s: str
:rtype: int
"""
a_dict = {}
for i in range (len(s)):
if s[i] in a_dict:
a_dict[s[i]] += 1
else:
a_dict[s[i]] = 1
count = 0
unit = 0
for a_value in a_dict.values():
if a_value % 2 == 0:
count += a_value
else:
count += (a_value//2)*2
unit = 1
return count + unit
No comments:
Post a Comment