File tree 1 file changed +8
-27
lines changed
1 file changed +8
-27
lines changed Original file line number Diff line number Diff line change 1
1
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
+ }
29
8
}
9
+ return list ;
10
+ }
30
11
}
You can’t perform that action at this time.
0 commit comments