0ms 1-pass C-solution using XOR


  • 0
    D

    Here's my simpel 0ms C solution.

    char findTheDifference(char* s, char* t) {
        int length = strlen(t);
        char ret = 0;
        for (int i = 0 ; i < length ; i++)
        {
            ret ^= t[i];
            if(i < length - 1)
                ret ^= s[i];
        }
        return ret;
        
    }

Log in to reply
 

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