293 Flip Game
Problem:
Solutions:
public class Solution {
public List<String> generatePossibleNextMoves(String s) {
List<String> result = new LinkedList<String>();
StringBuilder sb = new StringBuilder(s);
for (int i = 0; i < s.length() - 1; i ++) {
if (s.charAt(i) == '+' && s.charAt(i + 1) == '+') {
sb.setCharAt(i, '-');
sb.setCharAt(i + 1, '-');
result.add(sb.toString());
sb.setCharAt(i, '+');
sb.setCharAt(i + 1, '+');
}
}
return result;
}
}Last updated