class Solution:
"""
@param s: a string which consists of lowercase or uppercase letters
@return: the length of the longest palindromes that can be built
"""
def longestPalindrome(self, s):
# write your code here
ls = []
odd = 0
even = 0
for i in range(len(s)):
if s[i] in ls:
ls.remove(s[i])
even += 1
odd -= 1
else:
ls.append(s[i])
odd += 1
if odd > 0:
res = 2*even + 1
else:
res = 2*even
return resPython, LintCode, 627. 最长回文串
最新推荐文章于 2022-03-09 14:08:35 发布
本文介绍了一种求解最长回文子串的算法实现,该算法通过遍历字符串并利用哈希表来记录字符出现情况,最终计算出能够构成的最长回文串长度。
3万+

被折叠的 条评论
为什么被折叠?



