====== Longest Palindrome ====== * LeetCode는 사이트에서 제공하는 해설이 이미 충분히 친절하고, 구현도 단순해서 딱히 쓸 말이 없다. ===== 코드 ===== """Solution code for "LeetCode 409. Longest Palindrome". - Problem link: https://leetcode.com/problems/longest-palindrome/ - Solution link: http://www.teferi.net/ps/problems/leetcode/409 """ import collections class Solution: def longestPalindrome(self, s: str) -> int: paired_length = 0 unpaired_length = 0 counter = collections.Counter(s) for count in counter.values(): paired_length += (count // 2) * 2 if count % 2: unpaired_length = 1 return paired_length + unpaired_length