[C++/Python/Java] It is only easy when you think really hard to spot the built-in nature
idea\uFF1A count the frequency of each char, the chars appears even times can all be kept, however, the chars appears odd times must remove one char, then the r
idea\uFF1A count the frequency of each char, the chars appears even times can all be kept, however, the chars appears odd times must remove one char, then the rest instances of that char can be collected for composition. Finally, the middle char can be from OddGroup\nExample: "abccccdd",\nstep 1: count  freq of  char before clearning:    \na:1\nb:1\nc:4\nd:2\n\nstep 2: perform clearning and prepare for palindrom composition:\na:0\nb:0\nc:4\nd:2\nanswer = s.size() - 1 - 1\nStep 3: make correction, if necessary (i.e., when at least one char shows odd times)\nif OddGroup > 0: answer +=1\n\nRef: https://leetcode.com/problems/longest-palindrome/discuss/89587/What-are-the-odds-(Python-and-C%2B%2B)\n```\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        int freq[128]={};\n        for(auto c:s) ++freq[c];\n        int OddGroup = 0; //count of uniq char which shows up odd times, help me if you have better naming \n        for(auto i:freq) OddGroup += i & 1;\n        return s.size() - OddGroup + (OddGroup > 0);        \n    }\n};      \n```\n\nPython:\n```\nclass Solution:\n    def longestPalindrome(self, s: str) -> int:\n        freq = [0]*128;\n        for c in s:freq[ord(c)]+=1\n        OddGroup = 0\n        for i in freq: OddGroup += i & 1\n        return len(s) - OddGroup + (OddGroup > 0) \n```\n\nJava:\n```\nclass Solution {\n    public int longestPalindrome(String s) {\n        int[] freq = new int[128];        \n        for(char c:s.toCharArray()) ++freq[c];\n        int OddGroup = 0;\n        for(int i:freq) OddGroup += i & 1;\n        return s.length() - OddGroup + (OddGroup > 0 ? 1:0);  // Waiting for a better way to convert boolean into int  \n    }\n}\n```
['C', 'Python', 'Java']