74.Search a 2D Matrix

public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix == null || matrix[0][0] > target)
            return false;
        int rowLen = matrix.length;
        int colLen = matrix[0].length;
        int low = 0, high = rowLen * colLen - 1;

        while (low <= high) {
            int mid = (low + high) >>> 1;
            int x = mid / colLen;
            int y = mid % colLen;
            if (matrix[x][y] > target) {
                high = mid - 1;
            } else if (matrix[x][y] < target) {
                low = mid + 1;
            } else {
                return true;
            }
        }
        return false;
    }
原文地址:https://www.cnblogs.com/smallredness/p/10675702.html