Count Freq vs Even or Odd||0ms  beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nAt most one alphabet has an odd number of occurrencies in a palindrome string.\n\n2nd a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAt most one alphabet has an odd number of occurrencies in a palindrome string.\n\n2nd approach uses bitset/long long & consider only the parity ( odd or even frequencies). C, C++ & Python are implemented.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use an array `freq[58]`, since \'A\'=65~\'z\'=122, there 122-65+1=122-64=58 alphabets\n2. Count `freq`\n3. Use a loop to count the length of longest palindrome string; if f in freq is even, `len+=f`, otherwise `len+=f-1`, & set `hasOdd=1`\n4. `len+hasOdd` is the answer\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n+58)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(58)$$\n# Code||0ms  beats 100%\n```\nclass Solution {\npublic:\n    static int longestPalindrome(string& s) {\n        int freq[58]={0}; //\'A\'=65~\'z\'=122\n        for(char c: s)\n            freq[c-\'A\']++;\n        int len=0;\n        bool hasOdd=0;\n        for(int f: freq){\n            if ((f&1)==0) len+=f;\n            else{\n                len+=(f-1);\n                hasOdd=1;\n            }\n        }\n        return len+hasOdd;\n    }\n};\n\n\nauto init = []() {\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return \'c\';\n}();\n```\n# 2nd approach using even or odd for freq arguement||C, C++0ms beats 100%\n```C++ []\nclass Solution {\npublic:\n    static int longestPalindrome(string& s) {\n        bitset<58> freq=0; //\'A\'=65~\'z\'=122\n        for(char c: s)\n            freq.flip(c-\'A\');\n        int len=s.size();\n        for(int i=0; i<58; i++){\n            if (freq[i]) len--;//odd freq len-=1\n        }\n        return len+(freq.count()>=1);\n    }\n};\n\n\nauto init = []() {\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return \'c\';\n}();\n```\n```C []\n#pragma GCC optimize("O3", "unroll-loops")\nint longestPalindrome(char* s) {\n    long long freq=0; \n    int len=0;\n    for(register int i=0; s[i]!=\'\\0\'; i++){\n        freq^=(1LL<<(s[i]-\'A\'));\n        len++;\n    }\n    bool hasOdd=0;\n    for(register int i=0; i<58; i++){\n        if ((freq>>i)&1){\n            len--;\n            hasOdd=1;\n        }\n    }\n    return len+hasOdd;\n}\n```\n```Python []\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        freq=0\n        for c in s:\n            freq^=(1<<(ord(c)-ord(\'A\')))\n        L=len(s)\n        hasOdd=0\n        for i in range(58):\n            if ((freq>>i)&1)==1: \n                L-=1\n                hasOdd=1\n        return L+hasOdd\n```\n# 3rd C++ is a revised short form for the 2nd C++||0ms beats 100%\n```\nclass Solution {\npublic:\n    static int longestPalindrome(string& s) {\n        bitset<58> freq=0; //\'A\'=65~\'z\'=122\n        for(char c: s)\n            freq.flip(c-\'A\');\n        int odd=freq.count();\n        return s.size()-odd+(odd>=1);\n    }\n};\n```
['Array', 'String', 'Bit Manipulation', 'C', 'C++', 'Python3']