Difficult:Medium
題目
Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
1.Each row must contain the digits 1-9 without repetition.
2.Each column must contain the digits 1-9 without repetition.
3.Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
Note:
A Sudoku board (partially filled) could be valid but is not necessarily solvable.
Only the filled cells need to be validated according to the mentioned rules.
翻譯
確定 9 x 9 數獨板是否有效。只有填充的單元格需要根據以下規則進行驗證:
每行必須包含數字 1-9,不得重複。
每列必須包含數字 1-9,不得重複。
網格的九個 3 x 3 子框中的每一個都必須包含數字 1-9,且不得重複。
筆記:
數獨板(部分填充)可能是有效的,但不一定是可解的。
只有填充的單元格需要根據上述規則進行驗證。
範例
Example 1:
1 | Input: board = |
Example 2:
1 | Input: board = |
解題思路
1.直著檢查
2.橫的檢查
3.3x3方形檢查
Solution
Code 1 :
1 | var isValidSudoku = function (board) { |