Java solution using HashMap, 9ms
\n# Code\n\nclass Solution {\n    public int longestPalindrome(String s) {\n        int odd_count = 0;\n        HashMap<Character, Integer> map = new HashMap<>(
\n# Code\n```\nclass Solution {\n    public int longestPalindrome(String s) {\n        int odd_count = 0;\n        HashMap<Character, Integer> map = new HashMap<>();\n        for (char ch: s.toCharArray()){\n            map.put(ch, map.getOrDefault(ch, 0) + 1);\n            if (map.get(ch) % 2 == 1){\n                odd_count ++;\n            }\n            else{\n                odd_count--;\n            }\n        }\n        if (odd_count > 1){\n            return s.length() - odd_count + 1;\n        }\n        return s.length();\n    }\n}\n```
['Hash Table', 'Java']