File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 281
281
290|[ Word Pattern] ( ./solutions/0290-word-pattern.js ) |Easy|
282
282
291|[ Word Pattern II] ( ./solutions/0291-word-pattern-ii.js ) |Medium|
283
283
292|[ Nim Game] ( ./solutions/0292-nim-game.js ) |Easy|
284
+ 293|[ Flip Game] ( ./solutions/0293-flip-game.js ) |Easy|
284
285
295|[ Find Median from Data Stream] ( ./solutions/0295-find-median-from-data-stream.js ) |Hard|
285
286
297|[ Serialize and Deserialize Binary Tree] ( ./solutions/0297-serialize-and-deserialize-binary-tree.js ) |Hard|
286
287
299|[ Bulls and Cows] ( ./solutions/0299-bulls-and-cows.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 293. Flip Game
3
+ * https://leetcode.com/problems/flip-game/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are playing a Flip Game with your friend.
7
+ *
8
+ * You are given a string currentState that contains only '+' and '-'. You and your friend take
9
+ * turns to flip two consecutive "++" into "--". The game ends when a person can no longer make
10
+ * a move, and therefore the other person will be the winner.
11
+ *
12
+ * Return all possible states of the string currentState after one valid move. You may return
13
+ * the answer in any order. If there is no valid move, return an empty list [].
14
+ */
15
+
16
+ /**
17
+ * @param {string } currentState
18
+ * @return {string[] }
19
+ */
20
+ var generatePossibleNextMoves = function ( currentState ) {
21
+ const results = [ ] ;
22
+
23
+ for ( let i = 0 ; i < currentState . length - 1 ; i ++ ) {
24
+ if ( currentState [ i ] === '+' && currentState [ i + 1 ] === '+' ) {
25
+ results . push (
26
+ currentState . slice ( 0 , i ) + '--' + currentState . slice ( i + 2 )
27
+ ) ;
28
+ }
29
+ }
30
+
31
+ return results ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments