Skip to content

Commit a8aead1

Browse files
committed
solve problem Nim Game
1 parent 4ad8e10 commit a8aead1

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ All solutions will be accepted!
1111
|728|[Self Dividing Numbers](https://leetcode-cn.com/problems/self-dividing-numbers/description/)|[java/py/js](./algorithms/SelfDividingNumbers)|Easy|
1212
|804|[Unique Morse Code Words](https://leetcode-cn.com/problems/unique-morse-code-words/description/)|[java/py/js](./algorithms/UniqueMorseCodeWords)|Easy|
1313
|500|[Keyboard Row](https://leetcode-cn.com/problems/keyboard-row/description/)|[java/py/js](./algorithms/KeyboardRow)|Easy|
14-
|344|[Reverse String](https://leetcode-cn.com/problems/reverse-string/)|[java/py/js](./algorithms/ReverseString)|Easy|
14+
|344|[Reverse String](https://leetcode-cn.com/problems/reverse-string/)|[java/py/js](./algorithms/ReverseString)|Easy|
15+
|292|[Nim Game](https://leetcode-cn.com/problems/nim-game/description/)|[java/py/js](./algorithms/NimGame)|Easy|

algorithms/NimGame/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Nim Game
2+
This problem is easy to solve

algorithms/NimGame/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 % 4 != 0;
4+
}
5+
}

algorithms/NimGame/solution.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @param {number} n
3+
* @return {boolean}
4+
*/
5+
var canWinNim = function(n) {
6+
return n % 4 !== 0
7+
};

algorithms/NimGame/solution.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution(object):
2+
def canWinNim(self, n):
3+
"""
4+
:type n: int
5+
:rtype: bool
6+
"""
7+
# if the result of n % 4 != 0, you can remove the number of result, then you can win
8+
return n % 4 != 0

0 commit comments

Comments
 (0)