[LintCode] Search a 2D Matrix
public boolean searchMatrix(int[][] matrix, int target) { // write your code here if(matrix == null || matrix.length == 0) return false; int i = 0; int j = matrix[0].length-1; while(i < matrix.length && j >=0) { if(target == matrix[i][j]) return true; else if(target < matrix[i][j]) j--; else i++; } return false; }
Leave A Comment