📌📌 C++ || Hashmap || Greedy || Faster | Easy To Understand
Using Hashmap\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n\n   
* ***Using Hashmap***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n\n        unordered_map<string, int> mp;\n        \n        // insert all the words into map\n\n        for(auto word : words)\n        {\n            mp[word]++;\n        }\n\n        int count = 0;\n        \n        // odd will keep track of is there any odd occurance of word having both characters equal\n\n        bool odd = false;\n        \n        // traverse over map\n\n        for(auto x : mp)\n        {\n            // case 1 :- if both the characters of the word is equal\n            \n            if(x.first[0] == x.first[1])\n            {\n                // if occurance is even then take all the occurance\n                \n                if(x.second % 2 == 0)\n                {\n                    count += 2 * (x.second);\n                }\n                \n                // if the occurance is odd then take one less occurance\n                \n                else\n                {\n                    odd = true;\n\n                    count += 2 * (x.second - 1);\n                }\n            }\n            \n            // case 2 :- if both the characters of the word is not equal\n            \n            else\n            {\n                // search for the occurance of its reverse\n                \n                string rev = x.first;\n\n                reverse(rev.begin(), rev.end());\n                \n                // if the reverse is found, then take minimum occurance of the both\n\n                if(mp.count(rev))\n                {\n                    count += 4 * (min(mp[x.first], mp[rev]));\n                }\n                \n                // erase rev from map for avoiding duplicate ans.\n\n                mp.erase(rev);  \n            }\n        }\n        \n        // if odd is true then add 2\n\n        if(odd)\n        {\n            count += 2;\n        }\n\n        return count;\n    }\n};\n```
['Greedy', 'C', 'C++']