Python, C++,Java,||Faster than 100%||Short-Simple-Solution||BeginnerLevel
Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n___\n__\nQ
***Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome*.**\n___________________\n_________________\n***Q409. Longest Palindrome***\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\n\u2705 **Python  Code** :\n```\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        res = 0\n        for i in collections.Counter(s).values():\n            res += i // 2 * 2\n        return min(res+1, len(s))\n```\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\n\n\u2705 **Java Code** :\n```\nclass Solution {\n    public int longestPalindrome(String s) {\n        int[] count = new int[256];\n        int odds = 0;\n        for (int v = 0; v < s.length(); v++) {\n            char currChar = s.charAt(v);\n            count[currChar] += 1;\n            odds += (count[currChar] & 1) == 1 ? 1 : -1;\n        }\n        return s.length() - odds + (odds > 0 ? 1 : 0);\n    }\n}\n```\n\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\n\u2705 **C++  Code** :\n```\nclass Solution {\npublic:\n    int longestPalindrome(const string &s) \n    {\n        int count[128]{};\n        for (auto c : s) \n            ++count[c];\n        for (auto num : count) \n            count[0] += num & 1;\n        return s.size() - count[0] + (count[0] > 0);\n    }\n};\n```\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\nIf you like the solution, please upvote \uD83D\uDD3C\nFor any questions, or discussions, comment below. \uD83D\uDC47\uFE0F\n
['C', 'Python', 'Java']