240. 搜索二维矩阵 II + 思维
240. 搜索二维矩阵 II
LeetCode_240
题目描述
代码实现
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
if(matrix == null || matrix.length == 0)
return false;
int m = matrix.length;
int n = matrix[0].length;
int i = 0, j = n-1;
while(i < m && j >= 0){
if(target < matrix[i][j]){
j--;
}else if(target > matrix[i][j]){
i++;
}else return true;
}
return false;
}
}
Either Excellent or Rusty