Python | Leetcode Python题解之第409题最长回文串
题目:
题解:
class Solution:def longestPalindrome(self, s: str) -> int:ans = 0count = collections.Counter(s)for v in count.values():ans += v // 2 * 2if ans % 2 == 0 and v % 2 == 1:ans += 1return ans
题目:
题解:
class Solution:def longestPalindrome(self, s: str) -> int:ans = 0count = collections.Counter(s)for v in count.values():ans += v // 2 * 2if ans % 2 == 0 and v % 2 == 1:ans += 1return ans