(
int row,
int n,
Set<Integer> colSet,
Set<Integer> posDiagSet,
Set<Integer> negDiagSet)
| 10 | } |
| 11 | |
| 12 | private void backtrack( |
| 13 | int row, |
| 14 | int n, |
| 15 | Set<Integer> colSet, |
| 16 | Set<Integer> posDiagSet, |
| 17 | Set<Integer> negDiagSet) { |
| 18 | if (row == n) { |
| 19 | count += 1; |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | for (int col = 0; col < n; col++) { |
| 24 | if (colSet.contains(col) |
| 25 | || posDiagSet.contains(row + col) |
| 26 | || negDiagSet.contains(row - col)) { |
| 27 | continue; |
| 28 | } |
| 29 | colSet.add(col); |
| 30 | posDiagSet.add(row + col); |
| 31 | negDiagSet.add(row - col); |
| 32 | backtrack(row + 1, n, colSet, posDiagSet, negDiagSet); |
| 33 | colSet.remove(col); |
| 34 | posDiagSet.remove(row + col); |
| 35 | negDiagSet.remove(row - col); |
| 36 | } |
| 37 | } |
| 38 | } |
no test coverage detected