We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a0eeb8c commit 5cd5814Copy full SHA for 5cd5814
docs/dataStructures-algorithms/Backtracking-NQueens.md
@@ -41,7 +41,7 @@
41
若 row 行的棋子和 i 行的棋子在同一对角线,等腰直角三角形两直角边相等,即 row - i == Math.abs(result[i] - column)
42
43
布尔类型变量 isValid 的作用是剪枝,减少不必要的递归。
44
-```
+```java
45
public List<List<String>> solveNQueens(int n) {
46
// 下标代表行,值代表列。如result[0] = 3 表示第1行的Q在第3列
47
int[] result = new int[n];
@@ -104,7 +104,7 @@ row - i + n 的最大值为 2n(当row = n,i = 0时),故anti_diag的容
104
105
**解法二时间复杂度为O(n!),在校验相同列和相同对角线时,引入三个布尔类型数组进行判断。相比解法一,少了一层循环,用空间换时间。**
106
107
108
List<List<String>> resultList = new LinkedList<>();
109
110
0 commit comments