Skip to content

Commit 09464a8

Browse files
committed
Updated the SudokuSolver.java to required Style.
1 parent b60338e commit 09464a8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/main/java/com/thealgorithms/backtracking/SudokuSolver.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
package com.thealgorithms.backtracking;
22

33
/**
4-
* Solves a Sudoku of any level and prints solved Sudoku
4+
* Solves a Sudoku of any level and prints solved Sudoku.
5+
* This class is a utility and should not be instantiated.
56
* @author Indraneela Doradla (<a href="https://github.com/captiosus1">git-Indraneela Doradla</a>)
67
*/
78
public final class SudokuSolver {
89

10+
/**
11+
* Private constructor to prevent instantiation.
12+
*/
913
private SudokuSolver() {
10-
// Private constructor to prevent instantiation
14+
// Utility class
1115
}
1216

1317
/**
14-
* Solves the Sudoku using backtracking
18+
* Solves the Sudoku using backtracking.
1519
* @param board the Sudoku grid
1620
* @return boolean indicating if the Sudoku can be solved
1721
*/
1822
public static boolean solveSudoku(int[][] board) {
19-
int r = -1, c = -1;
23+
int r = -1;
24+
int c = -1;
2025
boolean isEmpty = true;
2126

22-
// Finding the first empty position
27+
// Find the first empty position
2328
for (int i = 0; i < board.length; i++) {
2429
for (int j = 0; j < board[0].length; j++) {
2530
if (board[i][j] == 0) {
@@ -29,7 +34,9 @@ public static boolean solveSudoku(int[][] board) {
2934
break;
3035
}
3136
}
32-
if (!isEmpty) break;
37+
if (!isEmpty) {
38+
break;
39+
}
3340
}
3441

3542
// If no empty position is found, the Sudoku is solved
@@ -52,7 +59,7 @@ public static boolean solveSudoku(int[][] board) {
5259
}
5360

5461
/**
55-
* Checks if placing a number at the given position is valid
62+
* Checks if placing a number at the given position is valid.
5663
* @param board the Sudoku grid
5764
* @param r row index
5865
* @param c column index
@@ -84,7 +91,7 @@ public static boolean isSafe(int[][] board, int r, int c, int val) {
8491
}
8592

8693
/**
87-
* Prints the Sudoku grid
94+
* Prints the Sudoku grid.
8895
* @param board the Sudoku grid
8996
*/
9097
public static void printSudoku(int[][] board) {

0 commit comments

Comments
 (0)