###### 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.

Hint:

If there are 5 stones in the heap, could you figure out a way to remove the stones such that you will always be the winner?

public class Solution {
public boolean canWinNim(int n) {

return n % 4 ==0 ? false : true;

}
}

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

2015-10-20 23:58:46

#### [LeetCode 292] Nim Game

2015-10-13 13:16:54

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

2016-06-10 21:01:45

#### nim游戏详解（易懂）

2017-04-15 16:57:43

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

2015-10-13 14:46:56

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

2016-05-10 17:17:39

#### LeetCode（292） Nim Game

2015-11-27 15:58:30

#### Misere Nim （Nim博弈）

2016-04-14 09:24:05

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

2016-08-07 11:34:03

#### hdoj3032 Nim or not Nim?（ 可分解尼姆 ）

2014-03-19 18:24:15

Nim Game