题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
参考题目解析后得出的答案,我觉得这道题中 变量自增的时候是前++还是后++没什么要求,我用了后++也过了。
public class Solution {
public boolean Find(int target, int [][] array) {
// 特判
int m = array.length,n = array[0].length;
if(m == 0 || n == 0) {
return false;
}
int r = 0, s = n - 1;
while(r < m && s >= 0) {
if(array[r][s] == target) {
return true;
}else if(array[r][s] > target) {
s--;
}else {
r++;
}
}
return false;
}
}