C++ 3ms


  • 0
    N
        int longestPalindrome(string s) {
            vector<int> temp(1000,0);
            int nums=0;
            int hadone=0;
            for (int i=0; i<s.size(); i++) {
                temp[s[i]]++;
                if (temp[s[i]]==2) {
                    nums+=2;
                    temp[s[i]]=0;
                    hadone-=s[i];
                }
                else if(temp[s[i]]==1)
                    hadone+=s[i];
            }
            if (hadone)  return nums+1;
            else         return nums;
        }
    

Log in to reply
 

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