Valid Sudoku
- Matrix
- Hash Set
- Simulation
Given a 9-by-9 Sudoku board represented by an array of nine strings, determine whether the filled cells are valid.
Each string contains nine characters. Digits 1 through 9 are filled cells and a period represents an empty cell. A valid board has no repeated digit in any row, column, or 3-by-3 box. The board does not need to be solvable.
Valid custom partial board
- Input
"board": ["1.34.6789", "45.789.23", ".89123.56", "234.6789.", ".6789.234", "8912345..", "34.678912", "6789.2345", "912345.78"]
- Output
true
Explanation: Every visible digit is unique within its row, column, and 3-by-3 box.
Repeated digit in the first row
- Input
"board": ["1.34.6781", "45.789.23", ".89123.56", "234.6789.", ".6789.234", "8912345..", "34.678912", "6789.2345", "912345.78"]
- Output
false
Explanation: The first row contains the digit 1 at both ends.
Constraints
- board.length is 9
- Every row has length 9
- Every character is a period or a digit from 1 through 9