Simple 0ms C solution


  • 0
    L

    The key point is to make sure only at most 1 odd character existing in the string:

    bool canPermutePalindrome(char* s) {
        if (s == NULL)
            return true;
            
        int occurance[128] = {0};
        
        int i;
        
        for (i = 0; i < strlen(s); i++) {
            occurance[s[i]]++;
        }
        int count = 0;
        for (i = 0; i < 128; i++) {
            if (occurance[i] % 2) {
                if (++count > 1) {
                    return false;
                }
            }
        }
        
        return true;
    }

Log in to reply
 

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