Javascript beats 100%, use Array.prototype.sort()


  • 0
    L
    var findTheDifference = function(s, t) {
        var sArr = s.split('');
        var tArr = t.split('');
        sArr.sort();
        tArr.sort();
        for(let i = 0; i < tArr.length; i++){
            if(!sArr[i] || sArr[i] !== tArr[i]){
                return tArr[i];
            }
        }
    };

Log in to reply
 

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