c++ solution with counter vector


  • 0
    int longestPalindrome(string s) {
        vector<int> countVec(256, 0);
        int ans = 0;
        for (auto c : s) {
        	if (++countVec[c - '\0'] % 2 == 0)
        		ans += 2;
        }
        if (ans < s.size())
        	ans++;
        return ans;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.