🔥Easiest Solution➡️All Language🔥🔥
Intuition\npython []\nclass Solution(object):\n    def longestPalindrome(self, s):\n        """\n        :type s: str\n        :rtype: int\n        """\n       
# Intuition\n```python []\nclass Solution(object):\n    def longestPalindrome(self, s):\n        """\n        :type s: str\n        :rtype: int\n        """\n        from collections import Counter\n        \n        counts = Counter(s)\n        length = 0\n        has_odd = False\n        \n        for count in counts.values():\n            length += (count // 2) * 2\n            if count % 2 == 1:\n                has_odd = True\n        \n        if has_odd:\n            length += 1\n        \n        return length\n\n```\n```Java []\nclass Solution {\n    public int longestPalindrome(String s) {\n        Map<Character, Integer> counts = new HashMap<>();\n        \n        for (char c : s.toCharArray()) {\n            counts.put(c, counts.getOrDefault(c, 0) + 1);\n        }\n        \n        int length = 0;\n        boolean hasOdd = false;\n        \n        for (int count : counts.values()) {\n            length += (count / 2) * 2;\n            if (count % 2 == 1) {\n                hasOdd = true;\n            }\n        }\n        \n        if (hasOdd) {\n            length += 1;\n        }\n        \n        return length;\n    }\n}\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1.Count Characters: Use a counter to count how many times each character appears in the string.\n\n2.Initialize Length and Odd Flag: Start with a length of 0 and a flag (has_odd) to check if there\'s any character with an odd count.\n\n3.Iterate Over Counts:\nFor each character count, add the largest even part of the count to the palindrome length.\nCheck if the count is odd. If it is, set the has_odd flag to True.\n\n4.Handle Odd Character: If there\'s any character with an odd count, add 1 to the length to place one odd character in the center.\n\n5.Return Result: Return the computed length of the longest possible palindrome.\n\n\n# Code\n```\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        unordered_map<char, int> counts;\n    \n    for (char c : s) {\n        counts[c]++;\n    }\n    \n    int length = 0;\n    bool hasOdd = false;\n    \n    for (auto& pair : counts) {\n        int count = pair.second;\n        length += (count / 2) * 2;\n        if (count % 2 == 1) {\n            hasOdd = true;\n        }\n    }\n    \n    if (hasOdd) {\n        length += 1;\n    }\n    \n    return length;\n    }\n};\n```\n![leetCodeUpvote.png](https://assets.leetcode.com/users/images/7a78bfe4-56f1-4a7f-a9cc-a944230ed286_1717460097.271034.png)\n\n
['Python', 'C++', 'Java']