Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e32cda9

Browse files
committedFeb 14, 2025
Add solution #292
1 parent 0dc4c02 commit e32cda9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
282|[Expression Add Operators](./0282-expression-add-operators.js)|Hard|
226226
283|[Move Zeroes](./0283-move-zeroes.js)|Easy|
227227
290|[Word Pattern](./0290-word-pattern.js)|Easy|
228+
292|[Nim Game](./0292-nim-game.js)|Easy|
228229
295|[Find Median from Data Stream](./0295-find-median-from-data-stream.js)|Hard|
229230
303|[Range Sum Query - Immutable](./0303-range-sum-query-immutable.js)|Easy|
230231
316|[Remove Duplicate Letters](./0316-remove-duplicate-letters.js)|Medium|

‎solutions/0292-nim-game.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 292. Nim Game
3+
* https://leetcode.com/problems/nim-game/
4+
* Difficulty: Easy
5+
*
6+
* You are playing the following Nim Game with your friend:
7+
* - Initially, there is a heap of stones on the table.
8+
* - You and your friend will alternate taking turns, and you go first.
9+
* - On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.
10+
* - The one who removes the last stone is the winner.
11+
*
12+
* Given n, the number of stones in the heap, return true if you can win the game assuming
13+
* both you and your friend play optimally, otherwise return false.
14+
*/
15+
16+
/**
17+
* @param {number} n
18+
* @return {boolean}
19+
*/
20+
var canWinNim = function(n) {
21+
return n % 4 !== 0;
22+
};

0 commit comments

Comments
 (0)
Please sign in to comment.