搜索算法题目
有序矩阵查找目标值
import java.util.*;
public class Solution {
public int[] findElement(int[][] mat, int n, int m, int x) {
// write code here
int row=0;
int col=m-1;
int[] ans=new int[2];
while(row<n&&col>=0){
if(x==mat[row][col]){
ans[0]=row;
ans[1]=col;
break;
}else if(x<mat[row][col]){
col--;
}else{
row++;
}
}
return ans;
}
}