# LeetCode之 Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.

1<=n<=3:   win

4=n:     lose

5<=n<=7:  win

8=n:     lose

....

class Solution {
public:
bool canWinNim(int n) {
return n%4 != 0;
}
};

#### LeetCode292——Nim Game(一行代码解决)

2015-10-20 23:58:46

#### [LeetCode 292] Nim Game

2015-10-13 13:16:54

#### LeetCode（292） Nim Game

2015-11-27 15:58:30

#### 【LeetCode从零单刷】Nim Game

2015-10-13 16:42:16

#### 292. Nim Game [easy] (Python)

2016-05-10 17:17:39

#### [leetcode-292]Nim Game(java)

2015-10-13 14:46:56

#### Nim游戏，Grundy函数介绍

2016-06-10 21:01:45

#### Misere Nim （Nim博弈）

2016-04-14 09:24:05

#### Nim 游戏及其变形

2016-12-22 20:25:37

#### ICG游戏博弈一________nim游戏模型

2016-08-07 11:34:03