Description
Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes must contain the digits 1-9 without repetition.
Examples
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"]]Output:
trueExplanation:
The board is valid.
Input:
board = [["8","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"]]Output:
falseExplanation:
The board violates Sudoku rules due to a duplicate digit in a row, column, or 3x3 sub-box.
Input:
board = [["1","2","3","4","5","6","7","8","9"],["4","5","6","7","8","9","1","2","3"],["7","8","9","1","2","3","4","5","6"],["2","3","1","5","6","4","8","9","7"],["5","6","4","8","9","7","2","3","1"],["8","9","7","2","3","1","5","6","4"],["3","1","2","6","4","5","9","7","8"],["6","4","5","9","7","8","3","1","2"],["9","7","8","3","1","2","6","4","5"]]Output:
trueExplanation:
This is a completely filled valid Sudoku board. Each row contains digits 1-9 exactly once, each column contains digits 1-9 exactly once, and each 3x3 sub-box contains digits 1-9 exactly once. This example demonstrates that a fully completed board can still be considered valid according to the rules.
Constraints
- •
board.length == 9 - •
board[i].length == 9 - •
board[i][j] is a digit 1-9 or '.'.