LeetCode第三十七题-实现数独

Sudoku Solver

问题简介:给定一个大小9*9的二维数组,输入部分数字,其它字符用’.‘代替,要求完成剩余数字的计算即字符’.‘处

数独的要求:

1.每个数字1-9必须在每行中恰好出现一次

2.每个数字1-9必须在每列中恰好出现一次

3.数字1-9中的每一个必须在网格的9个3×3子框中的每一个中恰好出现一次

举例:

输入:

[

[“5”,“3”,".",".",“7”,".",".",".","."],

[“6”,".",".",“1”,“9”,“5”,".",".","."],

[".",“9”,“8”,".",".",".",".",“6”,"."],

[“8”,".",".",".",“6”,".",".",".",“3”],

[“4”,".",".",“8”,".",“3”,".",".",“1”],

[“7”,".",".",".",“2”,".",".",".",“6”],

[".",“6”,".",".",".",".",“2”,“8”,"."],

[".",".",".",“4”,“1”,“9”,".",".",“5”],

[".",".",".",".",“8”,".",".",“7”,“9”]

]

即:

结果:填充未完成的部分,即红色数字位置

解法一:

利用递归的思路,逐个填充原字符’.'处的数字,当填充每个数字时进行判断,判断填充的数字是否有效,直到递归所有字符

小白刷题之路,请多指教— — 要么大器晚成,要么石沉大海

你可能感兴趣的:(LeetCode第三十七题-实现数独)