Open GH1995 opened 5 years ago
return
的是信任链
对于每个需要填数字的格子带入1到9,每代入一个数字都判定其是否合法,如果合法就继续下一次递归,结束时把数字设回'.'
,判断新加入的数字是否合法时,只需要判定当前数字是否合法,不需要判定这个数组是否为数独数组,因为之前加进的数字都是合法的,这样可以使程序更加高效一些
决定谁来消耗,这里没有人来消耗,一种新的模式
决定谁来拓展
j
作快拓展i
作慢拓展临界条件转换j >= 9
怎么办 (i, j + 1) - > (i, 9)-> (i + 1, 0)
判断当前字符
.
,说明可以拓展,用1~9
进行拓展 (i, j + 1)
(i, j + 1)
检查函数,主要检查的是传入的j
,检查board[i][j]
合法性
37. Sudoku Solver
Difficulty: Hard
Write a program to solve a Sudoku puzzle by filling the empty cells.
A sudoku solution must satisfy all of the following rules:
1-9
must occur exactly once in each row.1-9
must occur exactly once in each column.1-9
must occur exactly once in each of the 93x3
sub-boxes of the grid.Empty cells are indicated by the character
'.'
.A sudoku puzzle...
...and its solution numbers marked in red.
Note:
1-9
and the character'.'
.9x9
.Solution
Language: C++