Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number N
on the chalkboard. On each player’s turn, that player makes a move consisting of:
- Choosing any
x
with0 < x < N
andN % x == 0
. - Replacing the number
N
on the chalkboard withN - x
.
Also, if a player cannot make a move, they lose the game.
Return True
if and only if Alice wins the game, assuming both players play optimally.
爱丽丝和鲍勃轮流玩游戏,爱丽丝首先出发。
最初,黑板上有一个数字N. 在每个玩家的回合中,该玩家进行以下操作:
-
选择0 <x <N且N%x == 0的任何x。
-
用N - x替换黑板上的数字N.
此外,如果玩家无法移动,他们将失去游戏。
当且仅当Alice赢得比赛时才返回True,假设两个玩家都达到最佳状态。
Example 1:
Input: 2
Output: true
Explanation: Alice chooses 1, and Bob has no more moves.
Example 2:
Input: 3
Output: false
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
网上思路
-
总结奇偶性规律, 特别简单,一行代码
- 动态规划,没有看的太懂
- http://www.codeleading.com/article/2789848511/