My C solution. Nothing special


  • 0
    L
    char findTheDifference(char* s, char* t) {
        int* alph = (int *) calloc (256, sizeof (int));
    
        for (int c = 0; s[c] != '\0'; c++)
            alph[(int) s[c]]++;
        
        for (int c = 0; t[c] != '\0'; c++)
            alph[(int) t[c]]--;
        
        for (int c = 0; c < 256; c++)
            if (alph[c] != 0)
                return (char) c;
    
        // in case the input is s == t
        return 'x';
    }
    

Log in to reply
 

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