# 409. Longest Palindrome

{% embed url="<https://leetcode.com/problems/longest-palindrome/submissions/>" %}
Longest Palindrome
{% endembed %}

1. 统计字符出现次数然后进行遍历
2. 偶数字符直接加上，奇数字符的话，我们取出其最大偶数，
3. 有遇到过奇数字符，就需要在结果加1，但只能加最多一次，如果结果已经是奇数就代表加过了，不需要再加。

```python
class Solution:
    def longestPalindrome(self, s: str) -> int:
        length = 0
        count = collections.Counter(s)
        for i in count.values():
            if i % 2 == 0:
                length += i
            else: 
                if (length % 2 == 0):
                    length += 1
                length += (i-1)
        return length
```
