A/C python, beat 84.62%, easy to understand


  • 0
    W
    def generatePossibleNextMoves(self, s):
        """
        :type s: str
        :rtype: List[str]
        """
        #print "s = ", s
        res = []
    
        def findAllIndexes(string, substring):
            indexes = []
            for curIdx in range(len(string)):
                #print "curIdx = ", curIdx
                #print "string[curIdx:len(substring)] = ", string[curIdx:len(substring)+curIdx]
                if string[curIdx:len(substring)+curIdx] == substring:
                    indexes.append(curIdx)
                    res.append(s[0:curIdx] + "--" + s[curIdx + 2:])
            return indexes
    
        indexes = findAllIndexes(s, "++")
        #print "indexes = ", indexes
    
        # for idx in indexes:
        #     res.append(s[0:idx] + "--" + s[idx+2:])
    
        #print "res = ", res
    
        return res

Log in to reply
 

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