4ms O(1) space and O(n) time C++ short code


  • 1
    X
        char findTheDifference(string s, string t){
            char result = 0;
            for(int i = 0; i < s.size(); ++i)
                result ^= (s[i] ^ t[i]);
            return result ^ t[s.size()];
        }
    

Log in to reply
 

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