Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
- Each row must contain the digits
1-9without repetition. - Each column must contain the digits
1-9without repetition. - Each of the nine
3 x 3sub-boxes of the grid must contain the digits1-9without 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.
Examples
Example 1
Input: board = [[5,3,.,...],[6,.,.,1,9,5,...],[.,9,8,...],[8,...],[4,...],[7,...],[.,6,...],[.,...],[.,...]]
Output: true
Example 2
Input: board = [[8,3,.,...],[6,.,.,1,9,5,...],[.,9,8,...],[8,...],[4,...],[7,...],[.,6,...],[.,...],[.,...]]
Output: false
Two 8's appear in the top-left 3x3 sub-box, making the board invalid.
Constraints
board.length == 9board[i].length == 9board[i][j]is a digit1-9or'.'