# 409. Longest Palindrome

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.

This is case sensitive, for example `"Aa"` is not considered a palindrome here.

**Note:**\
Assume the length of given string will not exceed 1,010.

**Example:**

```
Input:
"abccccdd"

Output:
7

Explanation:
One longest palindrome that can be built is "dccaccd", whose length is 7.
```

#### 解题要点：

记录每个字符出现的频率，再遍历这个数组，把字符出现的频率次数加进最终返回值，如果是偶数，则可以直接回文；如果是奇数，-1以构成回文。最后如整串只要有出现奇数数字，则单独+1到返回值里。

```java
class Solution {
    public int longestPalindrome(String s) {
        int[] count = new int[128];
        for(char c : s.toCharArray()){
            count[c]++;
        }
        int res = 0, odd = 0;
        for(int cc : count){
            res += cc;
            if(cc % 2 == 1){
                res -= 1;
                odd += 1;
            }
        }
        int add = 0;
        if(odd > 0) add = 1;        
        return res + add;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zhongwen.gitbook.io/leetcode-report/easy/409.-longest-palindrome.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
