Concise c++ solution, 6 lines, 3ms


  • 1
    int longestPalindrome(string s) {
        int cnt[128] = {0}, r = 1;
        for (char c : s)
            cnt[c]++;
        for (int i : cnt)
            r += i & ~1;
        return min<int>(r, s.size());
    }
    

Log in to reply
 

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