:>!easy understand javascript solution


  • 0
    X

    var canConstruct = function(ransomNote, magazine) {
    for (var i=0; i<ransomNote.length; i++) {
    if (!magazine.includes(ransomNote[i])) {
    return false;
    }
    else {
    var indexi=magazine.indexOf(ransomNote[i]);
    magazine=magazine.substring(0,indexi)+magazine.substr(indexi+1, magazine.length-(indexi+1));
    }
    }
    return true;
    };


Log in to reply
 

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