Javascript was made for stuff like this


  • 0
    K
    var canConstruct = function(ransomNote, magazine) {
        var note = ransomNote.split(''), mag = magazine.split(''), t;
        return note.every(function(val){
           t = mag.indexOf(val);
          if(t === -1) return false;
           mag.splice(t, 1); 
          return true;
        });
    };
    

Log in to reply
 

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