A faster Javascripts solution with time of 104ms


  • 0
    D
    function checkA(s,t){
    var Array = [];
    for(var k=0;k<26;k++){
        Array[k]=0;
    }
    for(var i=0;i<s.length;i++){
        Array[(s.charCodeAt(i)-97)]++;
        Array[(t.charCodeAt(i)-97)]--;
    }
    for(var x=0;x<26;x++){
        if(Array[x] !== 0){
            return false;
        }
    }
    return true;
    

    }
    var isAnagram = function(s, t) {
    if(s.length !== t.length){
    return false;
    }
    else {
    return checkA(s,t);
    }
    };


Log in to reply
 

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