Share my JavaScript code runtime beat 100% javascript


  • 1
    M

    var generatePossibleNextMoves = function(s) {

    var ans = [];
    if (!s || s.length < 2) {
        return ans;
    }
    for (var pos = s.indexOf("++"); pos != -1; pos = s.indexOf("++", pos+1)) {
        s = s.substr(0, pos) + "--" + s.substr(pos+2);
        ans.push(s);
        s = s.substr(0, pos) + "++" + s.substr(pos+2);
    }
    return ans;
    

    };


Log in to reply
 

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