-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStairCase.java
More file actions
27 lines (27 loc) · 890 Bytes
/
StairCase.java
File metadata and controls
27 lines (27 loc) · 890 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
public class StairCase {
public static boolean SearchStairCase(int matrix[][] , int key) { // O(n+m) -- Time Complixity
int row =0, col = matrix.length-1;
while (row < matrix.length && col>=0) {
if (matrix[row][col] == key) {
System.out.println("Key Found at Index (" + row +"," + col + ")");
return true;
}
else if (key < matrix[row][col]) {
col--;
}
else {
row++;
}
}
System.out.println("Key not found !");
return false;
}
public static void main(String[] args) {
int matrix[][] = {{10,20,30,40},
{15,25,35,45},
{27,29,37,48},
{32,33,39,50}};
int key =33;
SearchStairCase(matrix,key);
}
}