I count how many letters appear an odd number of times. Because we can use **all** letters, except for each odd-count letter we must leave one, except one of them we can use.

Python:

```
def longestPalindrome(self, s):
odds = sum(v & 1 for v in collections.Counter(s).values())
return len(s) - odds + bool(odds)
```

C++:

```
int longestPalindrome(string s) {
int odds = 0;
for (char c='A'; c<='z'; c++)
odds += count(s.begin(), s.end(), c) & 1;
return s.size() - odds + (odds > 0);
}
```

Similar solutions (I actually like the `use`

solutions better than the above, but I'm just so fond of my topic title :-)

```
def longestPalindrome(self, s):
use = sum(v & ~1 for v in collections.Counter(s).values())
return use + (use < len(s))
def longestPalindrome(self, s):
counts = collections.Counter(s).values()
return sum(v & ~1 for v in counts) + any(v & 1 for v in counts)
int longestPalindrome(string s) {
int use = 0;
for (char c='A'; c<='z'; c++)
use += count(s.begin(), s.end(), c) & ~1;
return use + (use < s.size());
}
int longestPalindrome(string s) {
vector<int> count(256);
for (char c : s)
++count[c];
int odds = 0;
for (int c : count)
odds += c & 1;
return s.size() - odds + (odds > 0);
}
int longestPalindrome(string s) {
vector<int> count(256);
int odds = 0;
for (char c : s)
odds += ++count[c] & 1 ? 1 : -1;
return s.size() - odds + (odds > 0);
}
```