MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / queens

Method queens

java/0051-n-queens.java:11–26  ·  view source on GitHub ↗
(boolean[][] board, int row, List<List<String>> ans2)

Source from the content-addressed store, hash-verified

9 }
10
11 public void queens(boolean[][] board, int row, List<List<String>> ans2) {
12 //base case
13 if (row == board.length) {
14 ArrayList<String> ans = new ArrayList<String>();
15 createAnswer(board, ans);
16 ans2.add(ans);
17 return;
18 }
19 for (int col = 0; col < board.length; col++) {
20 if (isSafe(board, row, col)) {
21 board[row][col] = true;
22 queens(board, row + 1, ans2);
23 board[row][col] = false;
24 }
25 }
26 }
27
28 public void createAnswer(boolean[][] board, ArrayList<String> ans) {
29 for (int i = 0; i < board.length; i++) {

Callers 1

solveNQueensMethod · 0.95

Calls 3

createAnswerMethod · 0.95
isSafeMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected