美文网首页
294. Flip Game II

294. Flip Game II

作者: 我是你的果果呀 | 来源:发表于2016-12-08 11:54 被阅读0次

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.
For example, givens = "++++", return true. The starting player can guarantee a win by flipping the middle"++"to become"+--+".
Follow up:  Derive your algorithm's runtime complexity.

思路是先反转一下, 判断对手输赢状态, 把刚刚反转的回溯成最初的字符串, 免得影响下一个循环结果。 如果确定对手输了, 那我们一定赢了, 直到循环结束,都没发现对手输, 那一定是我们输了。

相关文章

  • 294. Flip Game II

    Description You are playing the following Flip Game with ...

  • 294. Flip Game II

    You are playing the following Flip Game with your friend:...

  • 294. Flip Game II

    You are playing the following Flip Game with your friend:...

  • Flip Game II

    https://www.lintcode.com/problem/flip-game-ii/description

  • Flip Game II

    题目You are playing the following Flip Game with your frien...

  • CUC-SUMMER-2-J

    J - Flip Game POJ - 1753 Flip game is played on a rectang...

  • LeetCode[15] - Flip Game II

    这个题目李特是屌炸天的。我飞了九牛二虎之力(路子对),但是代码写的七荤八素,好长好长好长好长的。结果正解,三四行就...

  • LintCode

    1042 Toeplitz Matrix Flip Game

  • 293. Flip Game

    Description You are playing the following Flip Game with ...

  • Flip Game

    题目You are playing the following Flip Game with your frien...

网友评论

      本文标题:294. Flip Game II

      本文链接:https://www.haomeiwen.com/subject/uhfsmttx.html