36 有效的數獨

2021-10-02 18:01:49 字數 1033 閱讀 1184

參考文獻

判斷乙個 9x9 的數獨是否有效。只需要根據以下規則,驗證已經填入的數字是否有效即可。

example

輸入:[

["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"]

]輸出:true

一次迴圈

對生成的容器判斷是否有重複,其中』.'的重複不予考慮

class solution 

vector>::iterator it;

for(it=board.begin();it!=board.end();it++) //行判斷

if(!isrepeat(*it)) return false;

for(it=board_transpose.begin();it!=board_transpose.end();it++) //列判斷

if(!isrepeat(*it)) return false;

for(it=board_box.begin();it!=board_box.end();it++) //3x3宮格判斷

if(!isrepeat(*it)) return false;

return true;

}};

c++ prime 第5版

36 有效數獨

判斷乙個 9x9 的數獨是否有效。只需要根據以下規則,驗證已經填入的數字是否有效即可。數字 1 9 在每一行只能出現一次。數字 1 9 在每一列只能出現一次。數字 1 9 在每乙個以粗實線分隔的 3x3 宮內只能出現一次。對於每乙個遍歷到的當前元素,需要知道該元素是否之前已在該行,該列,該小方陣裡出...

36 有效的數獨

判斷乙個 9x9 的數獨是否有效。只需要根據以下規則,驗證已經填入的數字是否有效即可。數字 1 9 在每一行只能出現一次。數字 1 9 在每一列只能出現一次。數字 1 9 在每乙個以粗實線分隔的 3x3 宮內只能出現一次。上圖是乙個部分填充的有效的數獨。數獨部分空格內已填入了數字,空白格用 表示。示...

36 有效的數獨

判斷乙個9x9的數獨是否有效。只需要根據以下規則,驗證已經填入的數字是否有效即可。數字1 9在每一行只能出現一次。數字1 9在每一列只能出現一次。數字1 9在每乙個以粗實線分隔的3x3宮內只能出現一次。上圖是乙個部分填充的有效的數獨。數獨部分空格內已填入了數字,空白格用 表示。輸入 5 3 7 6 ...