C++ - Easiest Beginner Friendly Sol || O(n) time and O(128) = O(1) space
Intuition of this Problem:\n Describe your first thoughts on how to solve this problem. \nNOTE - PLEASE READ APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITE
# Intuition of this Problem:\n<!-- Describe your first thoughts on how to solve this problem. -->\n**NOTE - PLEASE READ APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Approach for this Problem:\n1. Initialize two variables, oddCount to store the number of characters with an odd count of occurrences and an unordered map ump to store the count of each character in the string.\n2. Iterate through the string and for each character ch, increment the count of that character in the unordered map.\n3. If the count of the current character ch is odd, increment oddCount. If the count is even, decrement oddCount.\n4. If oddCount is greater than 1, return s.length() - oddCount + 1, which is the maximum length of a palindrome that can be formed by using all but one character with an odd count of occurrences.\n5. If oddCount is not greater than 1, return s.length(), which is the length of the original string, as all characters can be used to form a palindrome.\n<!-- Describe your approach to solving the problem. -->\n\n# Humble Request:\n- If my solution is helpful to you then please **UPVOTE** my solution, your **UPVOTE** motivates me to post such kind of solution.\n- Please let me know in comments if there is need to do any improvement in my approach, code....anything.\n- **Let\'s connect on** https://www.linkedin.com/in/abhinash-singh-1b851b188\n\n![57jfh9.jpg](https://assets.leetcode.com/users/images/c2826b72-fb1c-464c-9f95-d9e578abcaf3_1674104075.4732099.jpeg)\n\n# Code:\n```C++ []\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        int oddCount = 0;\n        unordered_map<char, int> ump;\n        for(char ch : s) {\n            ump[ch]++;\n            if (ump[ch] % 2 == 1)\n                oddCount++;\n            else    \n                oddCount--;\n        }\n        if (oddCount > 1)\n            return s.length() - oddCount + 1;\n        return s.length();\n    }\n};\n```\n```Java []\nclass Solution {\n    public int longestPalindrome(String s) {\n        int oddCount = 0;\n        Map<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                oddCount++;\n            else\n                oddCount--;\n        }\n        if (oddCount > 1)\n            return s.length() - oddCount + 1;\n        return s.length();\n    }\n}\n\n```\n```Python []\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        odd_count = 0\n        d = {}\n        for ch in s:\n            if ch in d:\n                d[ch] += 1\n            else:\n                d[ch] = 1\n            if d[ch] % 2 == 1:\n                odd_count += 1\n            else:\n                odd_count -= 1\n        if odd_count > 1:\n            return len(s) - odd_count + 1\n        return len(s)\n\n```\n\n# Time Complexity and Space Complexity:\n- Time complexity: **O(n)**, where n is the length of the string s. This is because we are iterating through the string only once.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(m)**, where m is the number of unique characters in the string. This is because we are using an unordered map to store the count of each character.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->
['Hash Table', 'C++', 'Java', 'Python3']