409. Longest Palindrome

####QUESTION: 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.

####EXPLANATION:

####SOLUTION:

``````public int longestPalindrome(String s) {
char[] chars = s.toCharArray();
HashMap<Character,Integer> map = new HashMap<>();
for(char ch:chars){
if(null==map.get(ch)){
map.put(ch,1);
}else{
int value = map.get(ch) + 1;
map.put(ch,value);
}
}
int count = 0;
Iterator<Character> iterator = map.keySet().iterator();
while(iterator.hasNext()){
Character next = iterator.next();
if(map.get(next)%2==0){
count+=map.get(next);
iterator.remove();
}else{
count+= map.get(next)/2 *2;
}
}
if(map.size()!=0)
count++;
return count;
}
``````
>