前端早早聊大会2022-低代码专场
private boolean isValid(List<String> solutionOfXMinus1, int i, int x) {
for (int rowIndex = 0; rowIndex < solutionOfXMinus1.size(); rowIndex++) {
// 例如: "...Q"
String row = solutionOfXMinus1.get(rowIndex);
int queenRowIndex = rowIndex + 1;
int queenColIndex = row.indexOf("Q") + 1;
// 在同一列
if (queenColIndex == i) {
return false;
}
// 在对角线
if (((queenRowIndex + queenColIndex) == (x + i)) || ((queenRowIndex - queenColIndex) == (x - i))) {
return false;
}
}
return true;
}