Simple Java solution with a set(NOT A MAP) and 10-lines code, easy understand
Noticed the unit of constructing palindrome is pair of char. So we don\'t need to count Characters but just make a minus. \nRefer to this code, it\'s self-expla
Noticed the unit of constructing palindrome is pair of char. So we don\'t need to count Characters but just make a minus. \nRefer to this code, it\'s self-explanatory.\n\n```\npublic int longestPalindrome(String s) {\n\tSet<Character> set = new HashSet<>();\n\tfor (char c : s.toCharArray()) {\n\t\tif (set.contains(c)) {\n\t\t\tset.remove(c);\n\t\t} else {\n\t\t\tset.add(c);\n\t\t}\n\t}\n\tint baseSize = s.length() - set.size();\n\tif (set.size() != 0) return baseSize + 1;\n\treturn baseSize;\n}\n```
['Java']