-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsin2dpart2.java
More file actions
30 lines (29 loc) · 947 Bytes
/
bsin2dpart2.java
File metadata and controls
30 lines (29 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class bsin2dpart2 {
public static boolean searchMatrix(int[][] matrix, int target) {
int n= matrix.length;
int m= matrix[0].length;
int low=0, high=n*m-1;
int row= 0;
int col= m-1;
while(row<n && col>=0)
{
if(matrix[row][col]==target)
{
return true;
}
else if(matrix[row][col]<target)
{
row++;
}
else{
col--;
}
}
return false;
}
public static void main(String[] args) {
int matrix[][]= {{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
int target= 24;
System.out.println(searchMatrix(matrix, target));
}
}