Problem · Array
Valid Sudoku
Learn this problemProblem statement
Determine whether a partially filled 9 x 9 Sudoku board is valid.
Each row, each column, and each of the nine 3 x 3 sub-boxes may contain each digit from 1 through 9 at most once. Empty cells contain ..
Validate only the filled cells; the board does not need to be solvable.
Function
isValidSudoku(board: char[][]) → booleanExamples
Example 1
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"]]return = trueNo filled row, column, or sub-box contains a repeated digit.
Example 2
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"]]return = falseThe upper-left sub-box contains two cells with digit 8.
Constraints
board.length == board[i].length == 9.- Every cell is
.or a digit from1through9.