3ms one pass int[8] solution we can reduce the int[8] to int actually


  • 0
    D
    class Solution {
    public:
        int longestPalindrome(string s) {
            int table[8] = {0};
            int cnt = 0;
            int sigle = 0;
            for(int i = 0; i < s.size(); i++){
               if(table[s[i] / 32] & (1 << s[i] % 32)){
                   cnt += 2;
                   sigle--;
               }else{
                   sigle++;
               }
               table[s[i] / 32] ^= (1 << s[i] % 32);
            }
            return sigle? cnt+1 : cnt;
        }
    

    };


Log in to reply
 

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