74 搜索二维矩阵

image.png

code

  1. class Solution {
  2. public boolean searchMatrix(int[][] matrix, int target) {
  3. if(matrix.length==0)
  4. return false;
  5. int i = 0;
  6. int j = matrix[0].length-1;
  7. while(i<matrix.length&&j>=0){
  8. if(matrix[i][j]==target)
  9. return true;
  10. else if(matrix[i][j]<target)
  11. i++;
  12. else
  13. j--;
  14. }
  15. return false;
  16. }
  17. }