public class FindANumInTwoSortedArray {
public static void main(String[] args) {
int[][] array = {{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};
FindANumInTwoSortedArray findANumInTwoSortedArray = new FindANumInTwoSortedArray();
int target = 4;
boolean result = findANumInTwoSortedArray.findTarget(array, target);
System.out.println(result);
}
public boolean findTarget(int[][] array, int target){
boolean findResult = false;
for(int i = 0; i < array.length; ++i){
if(array[i][array[i].length-1] >= target && array[i][0] <= target){
int start = 0;
int end = array[i].length-1;
while(start <= end){
int mid = (start+end)/2;
if(array[i][mid] > target){
end = mid-1;
}else if(array[i][mid] < target){
start = mid + 1;
}else{
findResult = true;
break;
}
}
}
if(array[i][0] > target){
break;
}
}
return findResult;
}
}