← 返回 meta 的题目列表Valid Sudoku Without Hash
类型:online_judge
Given a 9x9 Sudoku board, determine if it is valid. The board should be filled with digits 1 to 9 and empty spaces represented by '.'. Each column, row, and each of the nine 3x3 sub-boxes should contain all unique digits. You must not use a hash table to accomplish the task. Write a function to validate the Sudoku board.
Input: An array board representing the Sudoku board.
Output: Return a boolean indicating whether the Sudoku board is valid.
Example Input
board = [
['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']
]
Example Output
true
Constraints:
board.length == 9
board[i].length == 9
Digits 1-9 are represented as characters.
'.' is an empty space.
Example
Input
[['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']]