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 '.'.

leetCode 36. Valid Sudoku(数独) 哈希

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.

leetCode 36. Valid Sudoku(数独) 哈希

2.Each column must have the numbers 1-9 occuring just once.

leetCode 36. Valid Sudoku(数独) 哈希

3.And the numbers 1-9 must occur just once in each of the 9 sub-boxes of the grid.

leetCode 36. Valid Sudoku(数独) 哈希

题目大意:

判断一个给定的二维数组是否是一个合法的数独矩阵。

思路:

采用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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:leetCode36.ValidSudoku(数独)哈希-创新互联
转载注明:http://myzitong.com/article/ddsijh.html