C++ Solution
Code\n\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        unordered_map<string, int> mp;\n        for(auto x: words) mp[x]+
# Code\n```\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        unordered_map<string, int> mp;\n        for(auto x: words) mp[x]++;\n        int ans = 0, fl = 0;\n        for(auto x: words) {\n            if(x[0] == x[1]) {\n                if(mp[x] % 2) {\n                    fl = 1;\n                    ans += 2 * (mp[x] - 1);\n                    mp[x] = 0;\n                }\n                else {\n                    ans += 2 * mp[x];\n                    mp[x] = 0;\n                }\n            }\n        }\n        if(fl) ans += 2;\n        for(auto x: words) {\n            auto y = x;\n            reverse(y.begin(), y.end());\n            if(mp[x] > 0 and mp[y] > 0) {\n                ans += 4;\n                mp[x]--;\n                mp[y]--;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']