Javascript Solution


  • 1
    J

    In Javascript, the conversion between char and binary is not quite easy.

    /**
     * @param {string} s
     * @param {string} t
     * @return {character}
     */
    var findTheDifference = function(s, t) {
        var a=0, b=0;
        var charCode, i=0;
        while(s[i]){
            a^=s.charCodeAt(i).toString(2);
            b^=t.charCodeAt(i).toString(2);
            i++;
        }
        b^=t.charCodeAt(i).toString(2);
        charCode = parseInt(a^b,2);
        return String.fromCharCode(charCode);
    };
    

Log in to reply
 

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