```
public class Solution {
public int longestPalindrome(String s) {
int count[] = new int[128];
int odd = 0, even = 0;
for(int i = 0; i < s.length(); i++){
if(++count[s.charAt(i) - 'A'] % 2 == 0){
even ++; odd --;
}
else odd ++;
}
return even * 2 + (odd > 0 ? 1 : 0);
}
}
```