I think there is an issue with the question.


  • 0
    S

    I got a solution on other's website it passed all the test cases. However, I consider that there is a problem with the question. I mean, the result or the test cases sometimes are not correct.
    For example, for a 10 '+' string which is "++++++++++", the result of the test case is true, but I can proof that it should be false.

    (1)- means first player, (2) means second player.

    First scenario:
    If the first person started from the first two, the second player could just skip a '+', and the first player has no way to win.

    ++(1) +(skip) ++(2) +(skip) ++(1) ++(2)

    ++(1) +(skip) ++(2) ++(1) +(skip) ++(2)

    ++(1) +(skip) ++(2) ++(1) ++(2) +

    Second scenario:
    If the first person skipped the first '+', and the second person got the following two '+', then no matter the 1st person skip the next '+' or not, there is no way to win.

    +(skip) ++(1) ++(2) ++(1)+(skip) ++(2)+

    +(skip) ++(1) ++(2) +(skip) ++(1) ++(2)+

    Please let me know if I didn't make it clear or my thought is wrong. I am so confused with the question and I am even more confused with why those answer could pass in the test cases? Here is the one I found that could pass the test cases but I am not sure if the logic is correct.

    public boolean canWin(String s) {
        for (int i = 0; i < s.length() - 1; ++i)
            if (s.charAt(i) == '+' && s.charAt(i + 1) == '+' && !canWin(s.substring(0, i) + "--" + s.substring(i + 2)))
                    return true;
        return false;
    }

  • 2

    You're wrong. That case is easily won simply by flipping the middle two and then mirroring the moves of the second player.


Log in to reply
 

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