Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@ -47,7 +47,14 @@ public class NQueens {
List<List<String>> arrangements = new ArrayList<List<String>>();
getSolution(queens, arrangements, new int[queens], 0);
if (arrangements.isEmpty()) {
System.out.println("There is no way to place " + queens + " queens on board of size " + queens + "x" + queens);
System.out.println(
"There is no way to place " +
queens +
" queens on board of size " +
queens +
"x" +
queens
);
} else {
System.out.println("Arrangement for placing " + queens + " queens");
}
@ -65,7 +72,12 @@ public class NQueens {
* @param columns: columns[i] = rowId where queen is placed in ith column.
* @param columnIndex: This is the column in which queen is being placed
*/
private static void getSolution(int boardSize, List<List<String>> solutions, int[] columns, int columnIndex) {
private static void getSolution(
int boardSize,
List<List<String>> solutions,
int[] columns,
int columnIndex
) {
if (columnIndex == boardSize) {
// this means that all queens have been placed
List<String> sol = new ArrayList<String>();
@ -99,7 +111,11 @@ public class NQueens {
* @param columnIndex: column in which queen is being placed
* @return true: if queen can be placed safely false: otherwise
*/
private static boolean isPlacedCorrectly(int[] columns, int rowIndex, int columnIndex) {
private static boolean isPlacedCorrectly(
int[] columns,
int rowIndex,
int columnIndex
) {
for (int i = 0; i < columnIndex; i++) {
int diff = Math.abs(columns[i] - rowIndex);
if (diff == 0 || columnIndex - i == diff) {