Posted on

Description

Submission

class Solution {
public:
    int longestPalindrome(string s) {
        map<char, int> cnt;
        int len = 0;
        for(auto ch: s) {
            ++cnt[ch];
            if(cnt[ch] >= 2) {
                cnt[ch] -= 2;
                len += 2;
            }
        }

        for(auto it: cnt) {
            if(it.second) {
                ++len;
                break;
            }
        }

        return len;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *