Correct column pointer initialization in RowColumnWiseSorted2dArrayBinarySearch (#6333)

This commit is contained in:
codingmydna
2025-07-02 21:51:56 +09:00
committed by GitHub
parent ebf5c3d326
commit 712ada5102
2 changed files with 128 additions and 1 deletions

View File

@ -29,7 +29,7 @@ public class RowColumnWiseSorted2dArrayBinarySearch implements MatrixSearchAlgor
public static <T extends Comparable<T>> int[] search(T[][] matrix, T target) {
int rowPointer = 0; // The pointer at 0th row
int colPointer = matrix.length - 1; // The pointer at end column
int colPointer = matrix[0].length - 1; // The pointer at end column
while (rowPointer < matrix.length && colPointer >= 0) {
int comp = target.compareTo(matrix[rowPointer][colPointer]);