My javascript solution


  • 6
    C
    
    var canConstruct = function(ransomNote, magazine) {
        if (ransomNote.length > magazine.length) { return false; }
        var ransomNoteArr = ransomNote.split('');
        var oldMagazineLength = magazine.length;
        ransomNoteArr.forEach(function(item,index){
            magazine = magazine.replace(item,'');
        });
        if(oldMagazineLength == magazine.length +ransomNoteArr.length) {
            return true;
        } else {
            return false;
        }
    };
    

  • 0
    T

    The most straight-forward answer i've ever seen. Thanks


Log in to reply
 

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