Skip to content

Commit db46f93

Browse files
committed
Add Solution.java for 0292.Nim Game
1 parent 87c85ed commit db46f93

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

solution/0292.Nim Game/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Nim Game
2+
3+
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.
4+
5+
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.
6+
7+
8+
## Example:
9+
```
10+
**Input**: 4
11+
**Output**: false
12+
**Explanation**: If there are 4 stones in the heap, then you will never win the game;
13+
  No matter 1, 2, or 3 stones you remove, the last stone will always be
14+
  removed by your friend.
15+
```

solution/0292.Nim Game/Solution.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution {
2+
public boolean canWinNim(int n) {
3+
return (n & 3) != 0;// n%4 != 0
4+
}
5+
}

0 commit comments

Comments
 (0)