Python | Easy
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        char_count = {}\n        \n     
[see the Successfully Accepted Submission](https://leetcode.com/problems/longest-palindrome/submissions/1277058488/?envType=daily-question&envId=2024-06-04)\n\n# Code\n```\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        char_count = {}\n        \n        # Count frequency of each character\n        for char in s:\n            if char in char_count:\n                char_count[char] += 1\n            else:\n                char_count[char] = 1\n        \n        length_of_palindrome = 0\n        odd_count_found = False\n        \n        # Calculate the length of the longest palindrome\n        for count in char_count.values():\n            if count % 2 == 0:\n                length_of_palindrome += count\n            else:\n                length_of_palindrome += count - 1\n                odd_count_found = True\n        \n        # If there was at least one character with an odd count, we can place one in the middle\n        if odd_count_found:\n            length_of_palindrome += 1\n        \n        return length_of_palindrome\n\n```\n![image](https://assets.leetcode.com/users/images/b1e4af48-4da1-486c-bc97-b11ae02febd0_1696186577.992237.jpeg)
['Python3']