-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlip.java
More file actions
31 lines (31 loc) · 882 Bytes
/
Copy pathFlip.java
File metadata and controls
31 lines (31 loc) · 882 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
31
package leetcode;
import java.util.*;
public class Flip {
public List<String> generatePossibleNextMoves(String s) {
List<String> ret = new ArrayList<String>();
char[] array = s.toCharArray();
for(int i=0; i<array.length-1; i++){
if(array[i] == '+' && array[i+1] == '+'){
flip(array,i,i+1);
ret.add(new String(array));
flip(array,i,i+1);
}
}
return ret;
}
private void flip(char[] array,int i, int j){
if(array[i] == '+'){
array[i] = '-';
array[j] = '-';
}
else{
array[i] = '+';
array[j] = '+';
}
}
public static void main(String[] args) {
Flip f = new Flip();
String s = "++++--++";
System.out.println(f.generatePossibleNextMoves(s));
}
}