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 res
Python, LintCode, 627. 最长回文串
猜你喜欢
转载自blog.csdn.net/u010342040/article/details/80264643
今日推荐
周排行