def searchMatrix(self, mat, target):
        """
        Binary search

        Multiple round of binary search
        possible to swap m and n, depends on the size
        O(m log n) or O(n log m)
        Practically: 204 ms

        :type mat: list[int][int]
        :type target: int
        :rtype: bool
        """
        m = len(mat)
        n = len(mat[0])

        col = [mat[i][0] for i in xrange(m)]
        row_by_first = self.bin_search(col, target)

        col = [mat[i][-1] for i in xrange(m)]
        row_by_last = self.bin_search(col, target, False)

        for i in range(row_by_first, row_by_last-1, -1):
            col = self.bin_search(mat[i], target)
            if mat[i][col] == target:
                return True

        return False
dataset/ETHPy150Open algorhythms/LeetCode/240 Search a 2D Matrix II.py/SolutionBinSearch.searchMatrix/original