mirror of
https://github.com/krahets/hello-algo.git
synced 2026-05-04 19:50:55 +08:00
feat(csharp) .NET 8.0 code migration (#966)
* .net 8.0 migration * update docs * revert change * revert change and update appendix docs * remove static * Update binary_search_insertion.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -8,11 +8,11 @@ namespace hello_algo.chapter_backtracking;
|
||||
|
||||
public class n_queens {
|
||||
/* 回溯算法:N 皇后 */
|
||||
static void Backtrack(int row, int n, List<List<string>> state, List<List<List<string>>> res,
|
||||
void Backtrack(int row, int n, List<List<string>> state, List<List<List<string>>> res,
|
||||
bool[] cols, bool[] diags1, bool[] diags2) {
|
||||
// 当放置完所有行时,记录解
|
||||
if (row == n) {
|
||||
List<List<string>> copyState = new();
|
||||
List<List<string>> copyState = [];
|
||||
foreach (List<string> sRow in state) {
|
||||
copyState.Add(new List<string>(sRow));
|
||||
}
|
||||
@@ -39,11 +39,11 @@ public class n_queens {
|
||||
}
|
||||
|
||||
/* 求解 N 皇后 */
|
||||
static List<List<List<string>>> NQueens(int n) {
|
||||
List<List<List<string>>> NQueens(int n) {
|
||||
// 初始化 n*n 大小的棋盘,其中 'Q' 代表皇后,'#' 代表空位
|
||||
List<List<string>> state = new();
|
||||
List<List<string>> state = [];
|
||||
for (int i = 0; i < n; i++) {
|
||||
List<string> row = new();
|
||||
List<string> row = [];
|
||||
for (int j = 0; j < n; j++) {
|
||||
row.Add("#");
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class n_queens {
|
||||
bool[] cols = new bool[n]; // 记录列是否有皇后
|
||||
bool[] diags1 = new bool[2 * n - 1]; // 记录主对角线是否有皇后
|
||||
bool[] diags2 = new bool[2 * n - 1]; // 记录副对角线是否有皇后
|
||||
List<List<List<string>>> res = new();
|
||||
List<List<List<string>>> res = [];
|
||||
|
||||
Backtrack(0, n, state, res, cols, diags1, diags2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user