Accepted 3ms C++ solultion


  • 0
    S
    class Solution {
    public:
        int longestPalindrome(string s) {
            if(!s.size()) return 0;
            int ans=0;
            int count[58]={0};//from 'A' to 'z' ,we need 26+6+26 
            for(char i:s){//count even
                if(!(++count[i-'A']%2))
                    ans+=2;
            }
            if(ans<s.size())//can add an odd
                ans++;
            return ans;
        }
    };
    

Log in to reply
 

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