[leetcode] 37. Sudoku Solver

网友投稿 260 2022-09-15

[leetcode] 37. Sudoku Solver

Description

Write a program to solve a Sudoku puzzle by filling the empty cells.

A sudoku solution must satisfy all of the following rules:

The given board contain only digits 1-9 and the character ‘.’.You may assume that the given Sudoku puzzle will have a single unique solution.The given board size is always 9x9.

分析

题目的意思是:求解数独。

思路很直接,一个深度优先搜索的问题。是一个hard类型的题目,所以比一般的dfs类型的题目要难,数组是一个矩阵,所以要双重循环遍历所有的位置,在每个位置填写数字后,要判断这个数字是否符合题目要求的三个限制。

代码

class Solution {public: void solveSudoku(vector>& board) { solve(board); } bool solve(vector>& board){ int n=board.size(); for(int i=0;i>& board,int row,int col,char num){ int n=board.size(); for(int i=0;i

参考文献

​​[编程题]sudoku-solver​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:[leetcode] 78. Subsets
下一篇:两会|董明珠再度建议:提高个税起征点至1万元/月!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~