[Python] Hash Table faster than 99.88%
Upvote If you like it \uFF1A\uFF09\n\n\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        count = {} # Hash Table   \n        ans = []  
Upvote If you like it \uFF1A\uFF09\n\n```\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        count = {} # Hash Table   \n        ans = []   # every word\'s frequency \n        odd= 0     # store an odd number\'s frequency \n        for word in s:\n            if word not in count:\n                count[word] = 1\n            else:\n                count[word] += 1\n        for times in count.values():\n            ans.append(times)\n            if times % 2 != 0:\n                odd += 1      # calculate an odd number\'s frequency\n        if odd != 0:\n            return sum(ans) - odd + 1        \n        elif odd == 0:\n            return sum(ans) - odd\n```\n![](https://assets.leetcode.com/users/images/629d1017-c172-4566-978d-abfc09c29f4f_1668938971.3741477.png)\n
['Hash Table', 'Python', 'Python3']