leetCode36.ValidSudoku(数独)哈希
36. Valid Sudoku(合法数独)
专注于为中小企业提供成都做网站、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业定襄免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'
.
A partially filled sudoku which is valid.
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
关于数独的简介:
There are just 3 rules to Sudoku.
1.Each row must have the numbers 1-9 occuring just once.
2.Each column must have the numbers 1-9 occuring just once.
3.And the numbers 1-9 must occur just once in each of the 9 sub-boxes of the grid.
题目大意:
判断一个给定的二维数组是否是一个合法的数独矩阵。
思路:
采用set这一容器,来进行去重。
1.判断每一行是否合法。
2.判断每一列是否合法。
3.判断每一个九宫格是否合法。
代码如下:
class Solution { public: bool isValidSudoku(vector>& board) { set mySet; //1.判断每一行是否合法 for (int row = 0; row < 9; row++) { //cout<<"检测行:"< |
2016-08-13 12:21:54
标题名称:leetCode36.ValidSudoku(数独)哈希
文章路径:http://scyanting.com/article/igcgjs.html