Javascript use char difference


  • 0
    O
    var findTheDifference = function(s, t) {
        var tLen = t.length;
        var sSum = 0;
        var tSum = 0;
        for(var i=0; i<tLen; i++){
            tSum += t.charCodeAt(i);
            
            if(i<tLen-1){
                sSum += s.charCodeAt(i)
            }
        }
        
        return String.fromCharCode(tSum - sSum);
    };
    

Log in to reply
 

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