c++ bit manipulation (O(n))


  • 0

    a ^ a = 0

    char findTheDifference(string s, string t) {
        char c = 0;
        for (int i = 0; i < t.size(); ++i) {
            c ^= (i < s.size()) ? s[i] : 0;
            c ^= t[i];
        }
        return c;
    }
    

Log in to reply
 

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