627. Longest Palindrome
class Solution {
public:
/**
* @param s: a string which consists of lowercase or uppercase letters
* @return: the length of the longest palindromes that can be built
*/
int longestPalindrome(string &s) {
// write your code here
int res = 0;
unordered_set <int> set;
for (int i = 0; i < s.size(); i ++){
if (set.count(s[i]) == 0)
set.insert(s[i]);
else{
set.erase(s[i]);
res += 2;
}
}
if (!set.empty()){
res ++;
}
return res;
}
};