board is a 9 × 9 Sudoku puzzle. Each cell holds a digit from "1" to "9", or "." when it is empty. Fill every empty cell so that the finished grid follows all three rules:
The digits already on the board stay where they are. Every puzzle given has exactly one solution.
Fill board itself. Your function returns nothing; the answer judged is board after your function has run.
Some cells are settled at once. In the fourth row, second column, the row already has 2 3 7 8 9, the column adds 4 5 6, and the box adds nothing new, so only 1 fits. Elsewhere you have to try a digit and back out when it leads to a dead end.
Only seven cells are empty. The third row is missing just a 4, and the fifth row just a 2. The fourth column is missing an 8, which leaves 5 for the other gap in the eighth row. The sixth column then needs a 3, and the fourth row's last two gaps take 4 and 2.
Constraints
board.length == 9board[i].length == 9board[i][j] is a digit from "1" to "9", or ".".Backtracking: take the empty cells in order, try each digit that doesn't already appear in that cell's row, column or box, and move on to the next cell. When a cell has no digit left to try, empty it and go back to change the previous one.