# 第一次做leetcode中Difficulty为easy的题-292

Nim Game My Submissions Question
Total Accepted: 20613 Total Submissions: 41521 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:
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) {
if (n<=0||n%4==0){
return false;
}
else{
return true;

}
}
}

1.代码非常简单，但是由于长时间没有使用Java（平时写算法都用对语法不严格的MATLAB），最基本的输入输出以及方法的定义都不记得了。应加强训练。

2.题目本身并不难，在解决问题的时候注意不要将问题复杂化。

#### Leetcode解题思路总结(Easy)

2015-12-17 17:12:03

#### leetcode刷题，总结，记录， 备忘 292

2015-10-25 16:16:24

#### LeetCode刷题 (Python) | 125. Valid Palindrome

2016-01-30 20:34:28

#### LeetCode刷题记录Easy篇（1）

2017-04-15 21:44:12

#### LeetCode Easy排序前50道题

2018-01-08 19:59:12

#### 第二次做leetcode中的难度为easy的题-258

2015-11-21 20:15:53

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

2015-10-20 23:58:46

#### 关于第一次在LeetCode上刷题的一点心得

2018-05-07 21:05:51

#### Python 学习 （Leetcode 算法题解【easy部分 技巧总结】）

2016-08-17 19:30:46

#### LeetCode高频题目（100）汇总-Java实现

2017-08-23 19:03:06