Skip to content

Commit 36ef64a

Browse files
committed
Fix checkstyle violations
1 parent 3a364c6 commit 36ef64a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/main/java/com/thealgorithms/matrix/Search2DMatrix.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
package com.thealgorithms.matrix;
22

33
/**
4-
* Search a 2D Matrix
4+
* Search a 2D Matrix.
55
* Reference: https://leetcode.com/problems/search-a-2d-matrix/
66
*/
77
public class Search2DMatrix {
88

9+
// Private constructor to satisfy Checkstyle utility class rule
10+
private Search2DMatrix() {
11+
throw new UnsupportedOperationException("Utility class");
12+
}
13+
14+
/**
15+
* Performs binary search on a 2D matrix.
16+
*
17+
* @param matrix the 2D matrix
18+
* @param target the value to search
19+
* @return true if found, false otherwise
20+
*/
921
public static boolean searchMatrix(int[][] matrix, int target) {
1022
if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
1123
return false;
@@ -20,11 +32,15 @@ public static boolean searchMatrix(int[][] matrix, int target) {
2032
int mid = (left + right) / 2;
2133
int midValue = matrix[mid / cols][mid % cols];
2234

23-
if (midValue == target) return true;
24-
else if (midValue < target) left = mid + 1;
25-
else right = mid - 1;
35+
if (midValue == target) {
36+
return true;
37+
} else if (midValue < target) {
38+
left = mid + 1;
39+
} else {
40+
right = mid - 1;
41+
}
2642
}
43+
2744
return false;
2845
}
2946
}
30-

0 commit comments

Comments
 (0)