Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f0ab976

Browse files
committed
Add solution #2029
1 parent 46e8823 commit f0ab976

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,696 LeetCode solutions in JavaScript
1+
# 1,697 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1556,6 +1556,7 @@
15561556
2025|[Maximum Number of Ways to Partition an Array](./solutions/2025-maximum-number-of-ways-to-partition-an-array.js)|Hard|
15571557
2027|[Minimum Moves to Convert String](./solutions/2027-minimum-moves-to-convert-string.js)|Easy|
15581558
2028|[Find Missing Observations](./solutions/2028-find-missing-observations.js)|Medium|
1559+
2029|[Stone Game IX](./solutions/2029-stone-game-ix.js)|Medium|
15591560
2033|[Minimum Operations to Make a Uni-Value Grid](./solutions/2033-minimum-operations-to-make-a-uni-value-grid.js)|Medium|
15601561
2037|[Minimum Number of Moves to Seat Everyone](./solutions/2037-minimum-number-of-moves-to-seat-everyone.js)|Easy|
15611562
2047|[Number of Valid Words in a Sentence](./solutions/2047-number-of-valid-words-in-a-sentence.js)|Easy|

solutions/2029-stone-game-ix.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 2029. Stone Game IX
3+
* https://leetcode.com/problems/stone-game-ix/
4+
* Difficulty: Medium
5+
*
6+
* Alice and Bob continue their games with stones. There is a row of n stones, and each stone has
7+
* an associated value. You are given an integer array stones, where stones[i] is the value of the
8+
* ith stone.
9+
*
10+
* Alice and Bob take turns, with Alice starting first. On each turn, the player may remove any
11+
* stone from stones. The player who removes a stone loses if the sum of the values of all
12+
* removed stones is divisible by 3. Bob will win automatically if there are no remaining stones
13+
* (even if it is Alice's turn).
14+
*
15+
* Assuming both players play optimally, return true if Alice wins and false if Bob wins.
16+
*/
17+
18+
/**
19+
* @param {number[]} stones
20+
* @return {boolean}
21+
*/
22+
var stoneGameIX = function(stones) {
23+
const remainderCount = [0, 0, 0];
24+
for (const stone of stones) {
25+
remainderCount[stone % 3]++;
26+
}
27+
28+
if (remainderCount[0] % 2 === 0) {
29+
return remainderCount[1] >= 1 && remainderCount[2] >= 1;
30+
}
31+
32+
return Math.abs(remainderCount[1] - remainderCount[2]) > 2;
33+
};

0 commit comments

Comments
 (0)