Simple short 0(n+m)


#1

public int solve(int[][] A, int B) {
int a[]=search(A,B);
if(a[0]==-1){
return -1;
}else{
a[0]++;
a[1]++;
return a[0]*1009+a[1];
}
}
public int[] search(int [][] A,int B){
int i=0,j=A[0].length-1;
int a[]=new int[2];
a[0]=a[1]=-1;
while(i<A.length && j>=0){
if(A[i][j]==B){
a[0]=i;
a[1]=j;
break;
}else if(A[i][j]>B){
j–;
}else{
i++;
}
}
return a;
}