board is a partly filled 9 × 9 Sudoku grid. Each cell holds a digit from "1" to "9", or "." when it is empty. Return true if the digits already placed break none of these rules, and false otherwise:
Only the filled cells are checked. Empty cells don't matter, and the board doesn't need to have a solution.
Every row, column and box holds each digit at most once.
This is Example 1 with a 4 added in the second row, eighth column. No other 4 shares its row or its column, but the top-right box already has a 4 in its first row.
This time a 1 is added in the top row, second column. The second column already has a 1, near the bottom.
Constraints
board.length == 9board[i].length == 9board[i][j] is a digit from "1" to "9", or ".".Each filled cell belongs to exactly one row, one column and one 3 × 3 box. The board is valid when no digit appears twice in any of those 27 groups.
You aren't asked to solve anything. The question is only whether the digits already on the board break a rule, and every rule has the same shape: inside one group of nine cells, no digit twice. That makes 27 groups in all, nine of each kind. Every cell sits in exactly three of them, one of each kind.
Time O(N²)Space O(N)
The full walkthrough and code are part of Premium
true