Simple C Solution.


  • 0
    S
    char findTheDifference(char* s, char* t) {
    #define LIST_LENGTH 'z' - 'a' + 1
        int char_list[LIST_LENGTH] = {0};
        int i = 0;
        for (; s[i]; ++i){
            ++char_list[s[i]-'a'];
            --char_list[t[i]-'a'];
        }
        --char_list[t[i]-'a'];
        for (int j = 0; j < LIST_LENGTH; ++j){
            if (char_list[j] == -1) return j + 'a';
        }
        return 'X';
    }
    

Log in to reply
 

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