Leetcode 294 Solution

This article provides solution to leetcode question 294 (flip-game-ii)

https://leetcode.com/problems/flip-game-ii

Solution

class Solution {
public:
    bool canWin(string s) {
        for (int i = 0; i + 1 < s.size(); i++)
        {
            if (s[i] == '+' && s[i + 1] == '+')
            {
                s[i] = s[i + 1] = '-';
                bool win = canWin(s);
                s[i] = s[i + 1] = '+';

                if (win == false)
                    return true;
            }
        }

        return false;
    }
};