Leetcode Problem 37. Sudoku Solver

37. Sudoku Solver

Leetcode Solutions

Key approach of the solution: Backtracking

  1. Start from the first cell of the board and proceed to the next empty cell.
  2. Try placing numbers from 1 to 9 in the current empty cell.
  3. For each number, check if it's a valid placement (not already present in the same row, column, or 3x3 sub-box).
  4. If the placement is valid, place the number and move to the next empty cell using recursion.
  5. If the placement leads to a dead end (no valid number can be placed in the next empty cell), backtrack by removing the last placed number and try the next one.
  6. Repeat steps 2-5 until the board is completely filled with a valid solution or all possibilities have been exhausted.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...