Valid Sudoku
MediumArrays & Hashing
Decode it first. Clues, constraints, pattern and plan before any code.A partly filled 9 by 9 Sudoku board is given as a list of 9 strings, one per row. Each character is a digit 1 to 9 or . for an empty cell. Return true if the board breaks no rule so far:
- no digit repeats in any row,
- no digit repeats in any column,
- no digit repeats in any of the nine 3 by 3 boxes.
Only the filled cells need to be checked. You do not have to decide whether the puzzle can be solved.
row 0 = "1.......1" → false (two 1s in row 0)
row 0 = "1........", row 1 = ".1......."
→ false (two 1s in the top-left box)
an empty board → trueConstraints
board.length == 9board[i].length == 9board[i][j]is a digit1-9or'.'.