题目来源:https://leetcode.com/problems/search-a-2d-matrix-ii
题目难度:Medium
解答1[Java]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class Solution { public boolean searchMatrix(int[][] matrix, int target) { if(matrix.length == 0){ return false; }
int row = 0; int column = matrix[0].length-1;
while(row<matrix.length&& column>=0){ if(target == matrix[row][column]){ return true; } else if(target > matrix[row][column]){ row++; } else{ column--; } }
return false; } }
|