for循环
public class Solution {
public boolean Find(int target, int [][] a) {
int rows=a.length;
int cols=a[0].length;
int i=rows-1;
int j=0;
for(;i>=0 && j<cols;){
if(target==a[i][j])
return true;
if(a[rows-1][cols-1]<target||a[0][0]>target )
return false;
if(target>a[i][j]){
j++;
}
if(target<a[i][j]){
i--;
}
}
return false;
}
}
while循环
public class Solution {
public boolean Find(int target, int [][] a) {
int rows=a.length;
int cols=a[0].length;
int i=rows-1;
int j=0;
while(i>=0 && j<cols){
if(target>a[i][j])
j++;
else if(target<a[i][j])
i--;
else
return true;
}
return false;
}
}