File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 256
256
| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [](src/WordPattern.java) [](python/word_pattern.py) | |
257
257
| 291 | 🔒 [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | |
258
258
| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | [](src/NimGame.java) [](python/nim_game.py) | |
259
- | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | | |
259
+ | 293 | 🔒 [Flip Game](https://leetcode.com/problems/flip-game) | [](src/FlipGame.java) | |
260
260
| 294 | 🔒 [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | |
261
261
| 298 | 🔒 [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | |
262
262
| 299 | [Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) | [](src/BullsAndCows.java) [](python/bulls_and_cows.py) | |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/flip-game
2
+ // N = |currentState|
3
+ // T: O(N^2)
4
+ // S: O(N^2)
5
+
6
+ import java .util .ArrayList ;
7
+ import java .util .List ;
8
+
9
+ public class FlipGame {
10
+ public List <String > generatePossibleNextMoves (String currentState ) {
11
+ final List <String > result = new ArrayList <>();
12
+ for (int i = 0 ; i < currentState .length () - 1 ; i ++) {
13
+ if (currentState .charAt (i ) == '+' && currentState .charAt (i + 1 ) == '+' ) {
14
+ result .add (flip (currentState , i ));
15
+ }
16
+ }
17
+ return result ;
18
+ }
19
+
20
+ private static String flip (String state , int index ) {
21
+ return state .substring (0 , index ) + "--" + state .substring (index + 2 );
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments