Skip to content

Commit b7f991f

Browse files
authored
Update Flip Game.java
1 parent 875122b commit b7f991f

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

Easy/Flip Game.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
class Solution {
2-
public static List<String> generatePossibleNextMoves(String s) {
3-
List<String> ans = new ArrayList<>();
4-
5-
if (s.length() < 2) {
6-
return ans;
7-
}
8-
9-
if (s.equals("--")) {
10-
return ans;
11-
}
12-
13-
int i = 0;
14-
while (i < s.length()-1) {
15-
if (s.charAt(i) == s.charAt(i+1) && s.charAt(i) == '+') {
16-
StringBuilder sb = new StringBuilder();
17-
sb.append(s.substring(0, i));
18-
sb.append('-');
19-
sb.append('-');
20-
sb.append(s.substring(i+2));
21-
22-
ans.add(sb.toString());
23-
}
24-
25-
i++;
26-
}
27-
28-
return ans;
2+
public List<String> generatePossibleNextMoves(String currentState) {
3+
List<String> list = new ArrayList<>();
4+
for (int i = 1; i < currentState.length(); i++) {
5+
if (currentState.charAt(i) == '+' && currentState.charAt(i - 1) == '+') {
6+
list.add(currentState.substring(0, i - 1) + "--" + currentState.substring(i + 1));
7+
}
298
}
9+
return list;
10+
}
3011
}

0 commit comments

Comments
 (0)