forked from varunu28/LeetCode-Java-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlip Game.java
More file actions
30 lines (24 loc) · 710 Bytes
/
Flip Game.java
File metadata and controls
30 lines (24 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public static List<String> generatePossibleNextMoves(String s) {
List<String> ans = new ArrayList<>();
if (s.length() < 2) {
return ans;
}
if (s.equals("--")) {
return ans;
}
int i = 0;
while (i < s.length()-1) {
if (s.charAt(i) == s.charAt(i+1) && s.charAt(i) == '+') {
StringBuilder sb = new StringBuilder();
sb.append(s.substring(0, i));
sb.append('-');
sb.append('-');
sb.append(s.substring(i+2));
ans.add(sb.toString());
}
i++;
}
return ans;
}
}