3ms C++ simple solution


  • 0
    Q
    class Solution {
    public:
        int longestPalindrome(string s) {
            vector<int> haha(256, 0);    
            int count = 0;
            for(int i = 0; i < s.length(); i++){
                if(haha[s[i]])  count += 2;
                haha[s[i]] = 1 - haha[s[i]];
            }
            return count == s.length() ? count : count + 1;
        }
    };
    

Log in to reply
 

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