privatevoidbacktrack(List<List<String>> resultList, int sideLength, List<String> rowList, int rowIndex, int columnIndex) { if (rowIndex == sideLength) { if (rowList.size() == sideLength) { resultList.add(newArrayList<>(rowList)); }
return; }
for (intindex= columnIndex; index < sideLength + columnIndex; index++) { intoffset= (index + 1) % sideLength;
if (!isSquareAvailable(rowIndex, offset)) { continue; }
// Description: Both entire row and column must be available. for (intindex=0; index < sideLength; index++) { if (squareStates[index][columnIndex] || squareStates[rowIndex][index]) { returnfalse; } }
// Description: From the current row to the top one, check if every top left and // top right one is available. for (intindex=0; index < rowIndex; index++) { intoffset= rowIndex - index; intleftSquareIndex= columnIndex - offset; intrightSquareIndex= columnIndex + offset;