Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:


	Integers in each row are sorted in ascending from left to right.
	Integers in each column are sorted in ascending from top to bottom.


&nbsp;
Example 1:

Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5
Output: true


Example 2:

Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20
Output: false


&nbsp;
Constraints:


	m == matrix.length
	n == matrix[i].length
	1 &lt;= n, m &lt;= 300
	-109 &lt;= matrix[i][j] &lt;= 109
	All the integers in each row are sorted in ascending order.
	All the integers in each column are sorted in ascending order.
	-109 &lt;= target &lt;= 109


class Solution(object):
    def searchMatrix(self, matrix, target):
        """
        :type matrix: List[List[int]]
        :type target: int
        :rtype: bool
        """
        found=False
        for X in matrix:
             for M in X:
                if M==target:
                    found=True
        return found
class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int rows = matrix.length;
        int cols = matrix[0].length;
        int lo = 0, hi = rows;
        while(lo + 1 < hi) {
            int mid = lo + (hi - lo) / 2;
            if (matrix[mid][0] <= target) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        int[] prospect;
        for (int i = 0; i <= lo; i++) {
            prospect = matrix[i];
            int l = 0;
            int h = cols;
            while (l + 1 < h) {
                int mid = l + (h - l) / 2;
                if (prospect[mid] <= target) {
                    l = mid;
                } else {
                    h = mid;
                }
            }
            if (prospect[l] == target) {
                return true;
            }
        }
        return false;
    }
}
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        for(int i=0;i<matrix.size();++i)
        {
            int s=0,e=matrix[0].size()-1;
            while(s<=e)
            {
                int mid=(s+e)/2;
                if(matrix[i][mid]>target)
                {
                    e=mid-1;
                }
                else if(matrix[i][mid]<target)
                {
                    s=mid+1;
                }
                else
                {
                    return true;
                }
            }
        }
        return false;
    }
};
function binarySearch(arr, target) {
    let low = 0;
    let high = arr.length - 1;

    while (low <= high) {
        let mid = parseInt((low + high) / 2);

        if (arr[mid] == target) {
            return mid;
        }
        else if (arr[mid] < target) {
            low = mid + 1;
        }
        else if (arr[mid] > target) {
            high = mid - 1;
        }
    }
    return -1;
}

var searchMatrix = function(matrix, target) {
    for (let i = 0; i < matrix.length; i++) {
        let check = binarySearch(matrix[i], target);

        if (check != -1) { return true }
    }
    return false
};
Search a 2D Matrix II