Straightforward python


  • 2
    B

    Just iterate the list, and append the valid move to the results.

    def generatePossibleNextMoves(self, s):
      
        if not s:
            return []
            
        res, i = [], 0
        while i < len(s)-1:
            if s[i:i+2] == "++":
                res.append(s[:i] + "--" + s[i+2:])
            i += 1
            
        return res

Log in to reply
 

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