A/C Python solution, easy to understand, beat 6.8%


  • 0
    W
    def canWin(self, s):
        #print "canWin s = ", s
    
        def helper(s):
    
            for i in range(len(s)-1):
                #print "i = ", i
    
                #print "s[i:i+2] = ",  s[i:i+2]
                #print "s[0:i] + -- + s[i+3:] = ", s[0:i] + "--" + s[i+2:]
                #select
                if (s[i:i+2] == "++"):
                    #recursive
                    win = helper(s[0:i] + "--" + s[i+2:])
    
                    if win == False:
                        return True
    
                #undo
    
            return False
    
        res = helper(s)
        #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.