Skip to content
Prev Previous commit
Next Next commit
Apply suggestions from code review
  • Loading branch information
siriak authored Jan 10, 2023
commit fc4d76dbb2c05908887cc597cc6253f7b193c2a8
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,18 @@ public int[] search(int[][] matrix, int value) {
int[] result = { -1, -1 };

while (i < n && j >= 0) {

if (matrix[i][j] == value) {
result[0] = i;
result[1] = j;
return result;
}
if (value > matrix[i][j]) {

i++;

} else {
j--;
}

}
return result;
}

public static void main(String[] args) {
int[][] matrix = {
{ 3, 4, 5, 6, 7 },
{ 8, 9, 10, 11, 12 },
{ 14, 15, 16, 17, 18 },
{ 23, 24, 25, 26, 27 },
{ 30, 31, 32, 33, 34 }
};

var search = new SearchInARowAndColWiseSortedMatrix();
int[] res = search.search(matrix, 26);
System.out.println(Arrays.toString(res));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public void notFound() {
int[] expectedResult = { -1, -1 };
assertArrayEquals(expectedResult, res);
}
}
}