[Java solution] Hash Table approach 78.41% faster
\nimport java.util.Hashtable;\nclass Solution {\n    public int longestPalindrome(String[] words) {\n        Hashtable<String,Integer> ht = new Hashtable<>();\n
```\nimport java.util.Hashtable;\nclass Solution {\n    public int longestPalindrome(String[] words) {\n        Hashtable<String,Integer> ht = new Hashtable<>();\n        int palindromeMax = 0;// to store the maximum count of palindrome for palindrome string. E.g. "bbbb"\n        int nonPalindromeMax = 0;// to store the maximum count of palindrome for non palindrome string. E.g. "abba" \n        String oddPalindromeMaxStr = "";// to store the string of maximum odd count of palindrome for palindrome string\n        int oddCountPalindromeMax = 0;// to store the maximum odd count of palindrome for palindrome string\n\t\t\n\t\t/*\n\t\t\tSolving logic\n\t\t\t1. We no need to care about the palindrome for non palindrome string. \n\t\t\tWe just need to record the cumulative of the palindrome for non palindrome string. \n\t\t\tBecause in any form, it also able to form palindrome while the prerequisites is it must be even count.\n\t\t\tExample: \n\t\t\t"abba" - Yes\n\t\t\t"abbaab" - No \n\t\t\t\n\t\t\t2. The case that we need to handle is palindrome for palindrome string.\n\t\t\tWe need to find the maximum odd count of palindrome for palindrome \n\t\t\tstring to put it at the middle of the palindrome. \n\t\t\tFor the even count of palindrome, we can just treat it as previous case, \n\t\t\tjust record cumulative of the count.\n\t\t\tFor those not the maximum odd count of palindrome for palindrome string,\n\t\t\twe just need to minus one to make it to even count.\n\t\t*/\n         \n\t\t//1st step: store all the string and count into hashtable\n        for(String word:words)\n        {\n            ht.put(word,ht.getOrDefault(word,0)+1);\n        }\n        \n\t\t//2nd step: find out the maximum odd count of palindrome for palindrome string\n        for(Map.Entry<String,Integer> m:ht.entrySet())\n        {\n            char[] charArr = m.getKey().toCharArray();\n            if(charArr[0]==charArr[1])\n            {\n                if(ht.get(m.getKey())%2!=0&&ht.get(m.getKey())>oddCountPalindromeMax)\n                {\n                    oddCountPalindromeMax = ht.get(m.getKey())*2;\n                    oddPalindromeMaxStr = m.getKey();\n                }\n            }\n        }\n        \n        for(Map.Entry<String,Integer> m:ht.entrySet())\n        {  \n            if(m.getKey().equals(oddPalindromeMaxStr))// if current string is the maximum odd count\n                continue;\n            char[] charArr = m.getKey().toCharArray();\n            if(charArr[0]==charArr[1])// palindrome for palindrome string\n            {\n                palindromeMax += m.getValue()%2==0?m.getValue()*2:(m.getValue()-1)*2;//if odd count then minus one\n            }\n            else{//palindrome for non palindrome string\n                String reverse = charArr[1]+""+charArr[0];\n                if(ht.containsKey(reverse))// find the pair\n                {\n                    nonPalindromeMax += Math.min(ht.get(reverse),m.getValue())*2;// get the min count between the pair\n                }\n            }\n        }\n\n        return nonPalindromeMax+palindromeMax+oddCountPalindromeMax;// at the end just add all\n    }\n}\n```
['Hash Table', 'Java']