File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 618
618
806|[ Number of Lines To Write String] ( ./0806-number-of-lines-to-write-string.js ) |Easy|
619
619
808|[ Soup Servings] ( ./0808-soup-servings.js ) |Medium|
620
620
809|[ Expressive Words] ( ./0809-expressive-words.js ) |Medium|
621
+ 810|[ Chalkboard XOR Game] ( ./0810-chalkboard-xor-game.js ) |Hard|
621
622
819|[ Most Common Word] ( ./0819-most-common-word.js ) |Easy|
622
623
821|[ Shortest Distance to a Character] ( ./0821-shortest-distance-to-a-character.js ) |Easy|
623
624
824|[ Goat Latin] ( ./0824-goat-latin.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 810. Chalkboard XOR Game
3
+ * https://leetcode.com/problems/chalkboard-xor-game/
4
+ * Difficulty: Hard
5
+ *
6
+ * You are given an array of integers nums represents the numbers written on a chalkboard.
7
+ *
8
+ * Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting
9
+ * first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to
10
+ * become 0, then that player loses. The bitwise XOR of one element is that element itself, and
11
+ * the bitwise XOR of no elements is 0.
12
+ *
13
+ * Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard
14
+ * equal to 0, then that player wins.
15
+ *
16
+ * Return true if and only if Alice wins the game, assuming both players play optimally.
17
+ */
18
+
19
+ /**
20
+ * @param {number[] } nums
21
+ * @return {boolean }
22
+ */
23
+ var xorGame = function ( nums ) {
24
+ const total = nums . reduce ( ( xor , num ) => xor ^ num , 0 ) ;
25
+ if ( total === 0 ) return true ;
26
+ return nums . length % 2 === 0 ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments