36. Valid Sudoku(合法數(shù)獨)
專注于為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)定襄免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
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.
關于數(shù)獨的簡介:
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.
題目大意:
判斷一個給定的二維數(shù)組是否是一個合法的數(shù)獨矩陣。
思路:
采用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(數(shù)獨)哈希
分享路徑:http://weahome.cn/article/igcgjs.html