A RegExp Javascript Solution


  • 0
    /**
     * @param {string} s
     * @param {string} t
     * @return {character}
     */
    var findTheDifference = function(s, t) {
        for(var i = 0; i < t.length; i += 1){
            var tempIndex = s.indexOf(t.charAt(i));
            if(tempIndex !== -1){
                var re = new RegExp(s.charAt(tempIndex));
                s = s.replace(re, '');
                t = t.replace(re, '');
                i -= 1;
            }
        }
        return t;
    };
    

Log in to reply
 

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