Flip Game II

Similar Problems:

You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive “++” into “–“. The game ends when a person can no longer make a move and therefore the other person will be the winner.

Write a function to determine if the starting player can guarantee a win.

Example:

Input: s = "++++" Output: true Explanation: The starting player can guarantee a win by flipping the middle "++" to become "+--+".

Follow up:

Derive your algorithm’s runtime complexity.

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.

## https://code.dennyzhang.com/flip-game-ii // Basic Ideas: simulation // // Complexity: Time ? Space ? func canWin(s string) bool { if len(s) <= 1 { return false } for i:=0; i+1<len(s); i++ { if s[i] == '+' && s[i+1] == '+' { s2 := s[0:i] + "--" + s[i+2:] if !canWin(s2) { return true } } } return false }