Closed congr closed 5 years ago
class Solution {
public int longestPalindrome(String s) {
char[] ch = s.toCharArray();
Map<Character, Integer> map = new HashMap();
for (char c : ch) map.merge(c, 1, Integer::sum);
int longest = 0;
for (int n : map.values()) // {a=2, b=5, c=2, d=3, e=3}
longest += (n/2) * 2;
return (s.length() > longest) ? longest+1 : longest;
}
}
https://leetcode.com/problems/longest-palindrome/