3 lines C++ solution using bit manipulation - 4ms

  • 1
    char findTheDifference(string s, string t) {
        for(int i=1;i<s.size();i++)
        return s[s.size()-1]^t[t.size()-1]^t[t.size()-2];
    Identical letters will be 0 after xor manipulation, the remain one is the letter added.

Log in to reply

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