Easy to understand accepted solution with explanation
First, characters are counted. Even occurring characters (v[i]%2 == 0) can always be used to build a palindrome. For every odd occurring character (v[i]%2 == 1)
First, characters are counted. Even occurring characters (v[i]%2 == 0) can always be used to build a palindrome. For every odd occurring character (v[i]%2 == 1), v[i]-1 characters can be used. Res is incremented if there is at least one character with odd occurrence number.\n```\n    int longestPalindrome(string s) {\n        vector<int> v(256,0);\n        for(int i = 0; i < s.size(); ++i)\n           ++v[s[i]];\n        int res = 0;\n        bool odd = false;\n        for(int i = 0; i < 256; ++i)\n           if(v[i]%2 == 0)\n               res += v[i];\n            else\n            {\n               res += v[i] - 1;\n               odd = true;\n            }\n        if(odd)\n          ++res;\n        return res;\n    }\n```
[]