Open Shawngbk opened 7 years ago
Solution1:
public class Solution { public List generatePossibleNextMoves(String s) { //if(s.length() <= 1) //return new ArrayList(); List res = new ArrayList(); for(int i = 0; i < s.length()-1; i++) { if(s.charAt(i) == '+' && s.charAt(i+1) == '+') { res.add(s.substring(0, i) + "--" + s.substring(i+2, s.length())); } } return res; } } —————————————————————————————————————————— solution2:
public List generatePossibleNextMoves(String s) { if(s.length() == 0) return new ArrayList<>(); List res = new ArrayList<>(); char[] chs = s.toCharArray(); for (int i = 0; i < chs.length - 1; i++) { if (chs[i] == '+' && chs[i + 1] == '+') { chs[i] = '-'; chs[i + 1] = '-'; res.add(String.valueOf(chs)); chs[i] = '+'; // Put back stuffs. chs[i + 1] = '+'; } } return res;
}
google
Solution1:
public class Solution { public List generatePossibleNextMoves(String s) {
//if(s.length() <= 1)
//return new ArrayList();
List res = new ArrayList();
for(int i = 0; i < s.length()-1; i++) {
if(s.charAt(i) == '+' && s.charAt(i+1) == '+') {
res.add(s.substring(0, i) + "--" + s.substring(i+2, s.length()));
}
}
return res;
}
}
——————————————————————————————————————————
solution2:
public List generatePossibleNextMoves(String s) {
if(s.length() == 0)
return new ArrayList<>();
List res = new ArrayList<>();
char[] chs = s.toCharArray();
for (int i = 0; i < chs.length - 1; i++) {
if (chs[i] == '+' && chs[i + 1] == '+') {
chs[i] = '-';
chs[i + 1] = '-';
res.add(String.valueOf(chs));
chs[i] = '+'; // Put back stuffs.
chs[i + 1] = '+';
}
}
return res;