File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 256256| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | [](src/WordPattern.java) [](python/word_pattern.py) | |
257257| 291 | π [Word Pattern II](https://leetcode.com/problems/word-pattern-ii) | | |
258258| 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) | |
260260| 294 | π [Flip Game II](https://leetcode.com/problems/flip-game-ii) | | |
261261| 298 | π [Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | |
262262| 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