📜  搜索 2D 矩阵 II - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:42.550000             🧑  作者: Mango

代码示例1
// Search a 2D Matrix II
// https://leetcode.com/problems/search-a-2d-matrix-ii
class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int row = 0;
        int col = matrix[0].length-1;
        
        while (row < matrix.length && col >= 0){
            if (matrix[row][col] == target) return true;
            if (matrix[row][col] < target) row++;
            else if (matrix[row][col] > target) col--;
        }
       return false;
    }
}