Skip to content

Commit a282d79

Browse files
nim game
1 parent 4325726 commit a282d79

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎EASY/src/easy/NimGame.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package easy;
2+
3+
public class NimGame {
4+
/**1. If there are only 1 or 2 or 3 stones, you could always win by taking 1 or 2 or 3 stones;
5+
* 2. If there are 4 stones, you could never win because no matter you tak 1 or 2 or 3 stones, you could never take the 4th one;
6+
* 3. If there are 5 or 6 or 7 stones, you could always win because no matter how your opponent works, you'll always get the last one;
7+
* 4. Then we could deduce that as long as the number is not divisible by 4, you could always win.*/
8+
9+
public boolean canWinNim(int n) {
10+
return n%4 != 0;
11+
}
12+
13+
}

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
|314|[Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/)|[Solution](../../blob/master/MEDIUM/src/medium/BinaryTreeVerticalOrderTraversal.java)| O(n)|O(n) | Medium| HashMap, BFS
1919
|301|[Remove Invalid Parentheses](https://leetcode.com/problems/remove-invalid-parentheses/)|[Solution]| ? | ? | Hard| BFS
2020
|283|[Move Zeroes](https://leetcode.com/problems/move-zeroes/)|[Solution](../../blob/master/EASY/src/easy/MoveZeroes.java)| O(n)|O(1) | Easy|
21+
|292|[Nim Game](https://leetcode.com/problems/nim-game/)|[Solution](../../blob/master/EASY/src/easy/NimGame.java)| O(1)|O(1) | Easy|
2122
|278|[First Bad Version](https://leetcode.com/problems/first-bad-version/)|[Solution](../../blob/master/EASY/src/easy/FirstBadVersion.java)| O(logn)|O(1) | Easy| Binary Search
2223
|273|[Integer to English Words](https://leetcode.com/problems/integer-to-english-words/)|[Solution]|
2324
|257|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)|[Solution](../../blob/master/EASY/src/easy/BinaryTreePaths.java) | O(n*h) | O(h) | DFS/Recursion

0 commit comments

Comments
 (0)