Python solution with detailed explanation

  • 0


    Flip Game

    • Just traverse the string and test adjacent characters.
    class Solution(object):
        def generatePossibleNextMoves(self, s):
            :type s: str
            :rtype: List[str]
            result, c = [], [ch for ch in s]
            for i in range(len(s)-1):
                if c[i] == "+" and c[i+1] == "+":
                    c[i], c[i+1] = "-", "-"
                    c[i], c[i+1] = "+", "+"
            return result

Log in to reply

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