Valid Sudoku
Determine if a 9x9 Sudoku board is valid. Only filled cells need to be validated: each row, column, and 3x3 box must contain digits 1-9 without repetition.
Input: 9 rows, each with 9 comma-separated values ('.' for empty).
Example
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
True
- The input is a 9x9 Sudoku board represented as 9 rows of comma-separated values, where '.' denotes an empty cell.
- We iterate over each row, column, and 3x3 box to check for duplicate digits (1-9), ignoring empty cells ('.').
- For each row, column, and box, we verify that all filled cells contain unique digits, i.e., no digit appears more than once: .
- Since no duplicates are found in any row, column, or box, the Sudoku board is valid, resulting in an output of
True.
Constraints
- board.length == 9
- board[i].length == 9
- board[i][j] is a digit or '.'