2131. Longest Palindrome by Concatenating Two Letter Words
Содержание
class Solution:
def longestPalindrome(self, words: List[str]) -> int:
cnt = Counter(words)
res = x = 0
for k, v in cnt.items():
if k[0] == k[1]:
x += v & 1
res += v // 2 * 2 * 2
else:
res += min(v, cnt[k[::-1]]) * 2
res += 2 if x else 0
return res