[practice js] a plain code...


  • 0
    M
    /**
     * @param {string} s
     * @return {string[]}
     */
    var generatePossibleNextMoves = function(s) {
        var result = [];
        for (var i = 0; i < s.length - 1; ++i) {
            if (s[i] === "+" && s[i + 1] === "+") {  // flip here
                var flipped = s.substring(0, i) + "--" + s.substring(i + 2);
                result.push(flipped);
            }
        }
        return result;
    };
    

Log in to reply
 

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