JavaScript Solution. Straightforward way


  • 0
    V

    The algorithm is simple: sort the characters and find the different one. Using the ASCII sum way is very smart and the XOR bit manipulation is also very smart.

    var findTheDifference = function(s, t) {
        var sChars = s.split('').sort();
        var tChars = t.split('').sort();
        var i;
        for(i = 0; i < sChars.length; i++) {
            if(tChars[i] !== sChars[i]) {
                return tChars[i];
            }
        }
        return tChars[i];
    };
    

Log in to reply
 

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