[3ms] C++ solution


  • 0
    L

    int longestPalindrome(string s)
    {
    int m[256] = {0}; // using array to implement "hash table"
    for(auto& k:s) m[k-'A']++;
    int rs = 0, oddFlag = 0;
    for(auto&n :m)
    {
    rs += (n%2==0) ? n : (n-1);
    if (n%2==1) oddFlag = 1;
    }
    return rs + oddFlag;
    }


Log in to reply
 

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