/**
* 查找函数的具体实现
* @author rayel
* */
public static int[] findInMatrix(int[][] matrix, int rows, int cols, int number){
int i=0,j=cols-1;
while((i<=rows-1)&&(j>=0)){
if (matrix[i][j]==number){
return new int[]{i,j};
}else if (matrix[i][j]>number){
j--;
}
else if (matrix[i][j]<number){
i++;
}
}
return null;
}
网友评论