Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 12, 2014 13:52
Show Gist options
  • Save Cee/e0dd1464bcbf19fe957f to your computer and use it in GitHub Desktop.
Save Cee/e0dd1464bcbf19fe957f to your computer and use it in GitHub Desktop.
public class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int height = matrix.length;
int width = matrix[0].length;
int i = -1;
int j = -1;
while (i <= height - 1){
if (i == height - 1) break;
if (target < matrix[i + 1][0]) break;
i++;
}
if (i == -1) i = 0;
while (j < width - 1){
if (target < matrix[i][j + 1]) return false;
if (target == matrix[i][j + 1]) return true;
if (target > matrix[i][j + 1]) j++;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment