File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,696 LeetCode solutions in JavaScript
1
+ # 1,697 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1556
1556
2025|[ Maximum Number of Ways to Partition an Array] ( ./solutions/2025-maximum-number-of-ways-to-partition-an-array.js ) |Hard|
1557
1557
2027|[ Minimum Moves to Convert String] ( ./solutions/2027-minimum-moves-to-convert-string.js ) |Easy|
1558
1558
2028|[ Find Missing Observations] ( ./solutions/2028-find-missing-observations.js ) |Medium|
1559
+ 2029|[ Stone Game IX] ( ./solutions/2029-stone-game-ix.js ) |Medium|
1559
1560
2033|[ Minimum Operations to Make a Uni-Value Grid] ( ./solutions/2033-minimum-operations-to-make-a-uni-value-grid.js ) |Medium|
1560
1561
2037|[ Minimum Number of Moves to Seat Everyone] ( ./solutions/2037-minimum-number-of-moves-to-seat-everyone.js ) |Easy|
1561
1562
2047|[ Number of Valid Words in a Sentence] ( ./solutions/2047-number-of-valid-words-in-a-sentence.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments