java sudoku solver

Solutions on MaxInterview for java sudoku solver by the best coders in the world

showing results for - "java sudoku solver"
Mattia
20 Aug 2016
1for (int row = 0; row < SIZE; row++) {
2         for (int col = 0; col < SIZE; col++) {
3          // we search an empty cell
4          if (board[row][col] == EMPTY) {
5            // we try possible numbers
6            for (int number = 1; number <= SIZE; number++) {
7              if (isOk(row, col, number)) {
8                // number ok. it respects sudoku constraints
9                board[row][col] = number;
10
11                if (solve()) { // we start backtracking recursively
12                  return true;
13                } else { // if not a solution, we empty the cell and we continue
14                  board[row][col] = EMPTY;
15                }
16             }
17            }
18
19            return false; // we return false
20           }
21          }
22         }
23
24         return true; // sudoku solved