<LeetCode OJ> 292. Nim Game

Total Accepted: 55175 Total Submissions: 105975 Difficulty: Easy

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:

1. 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?

8个，也就是两个4，我无论怎么摸石头都能让对手以4为一个坎最后摸完石头，所以必输

class Solution {
public:
bool canWinNim(int n) {
return n%4!=0;//卧槽，此题代码可以如此简单，意义何在？
}
};

LeetCode 292. Nim Game 题解（C++）

You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac...

Leetcode:292. Nim Game

Leetcode题解292.Nim Game-Easy题目

LeetCode 292: Nim Game 题解

• Artprog
• 2016年08月16日 23:18
• 387

LeetCode [292. Nim Game] 难度[easy]

LeetCode [292. Nim Game] 难度[easy]题目You are playing the following Nim Game with your friend: There is...

举报原因： 您举报文章： 292. Nim Game 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)