前端早早聊大會(huì)2022-低代碼專場(chǎng)
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;
? ? ? ? ? ?}
? ? ? ? ? ?// 在對(duì)角線
? ? ? ? ? ?if (((queenRowIndex + queenColIndex) == (x + i)) || ((queenRowIndex - queenColIndex) == (x - i))) {
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?return true;
? ?}
標(biāo)簽: