Simple C++ Solution


  • 0
    J

    '''

    int longestPalindrome(string s) {
        vector<int> cnt(52, 0);
        for (char c : s)
        {
            if (c >= 'a' && c <= 'z')
            {
                cnt[c - 'a']++;
            }
            else
            {
                cnt[c - 'A' + 26]++;
            }
        }
        
        int ret = 0, odd = 0;
        for (int x : cnt) 
        {
            ret += x/2*2;
            odd |= x & 1;
        }
        return ret + odd;
    }
    

    '''


Log in to reply
 

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