-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch In A 2D Matrix.java
More file actions
35 lines (34 loc) · 949 Bytes
/
Copy pathSearch In A 2D Matrix.java
File metadata and controls
35 lines (34 loc) · 949 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
31
32
33
34
35
import java.util.* ;
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static boolean BS(int start,int end,List<Integer> a,int target){
if(start<=end){
int mid = (start+end)/2;
if(a.get(mid)==target){
return true;
}
if(a.get(mid)>target){
return BS(start,mid-1,a,target);
}
else{
return BS(mid+1,end,a,target);
}
}
return false;
}
static boolean findTargetInMatrix(ArrayList<ArrayList<Integer>> mat, int m, int n, int target) {
// Write your code here.
List<Integer> temp = new ArrayList<>();
for(List<Integer> i : mat){
if(target<=i.get(n-1)){
temp = i;
break;
}
}
if(temp.size()==0){
return false;
}
return BS(0,n-1,temp,target);
}
}