力扣409. 最长回文串

原题链接

 1 class Solution:
 2     def longestPalindrome(self, s: str) -> int:
 3         dic = {}
 4         ans = bonus = 0
 5         for c in s:
 6             if c in dic:
 7                 dic[c] += 1
 8             else:
 9                 dic[c] = 1
10         for value in dic.values():
11             ans += value // 2 * 2
12             if value & 1 == 1:bonus = 1
13         return ans + bonus

 

posted @ 2021-01-24 16:37  凝视深空  阅读(78)  评论(0编辑  收藏  举报