boolean searchMatrix(int[][] a, int target) {
        if (a.length == 0 || a[0].length == 0) return false;
        for (int i = 0; i < a.length; i++) {
            int len = a[i].length - 1;
            if (a[i][0] == target || a[i][len] == target) return true;
            if (a[i][0] < target && Arrays.binarySearch(a[i], target) > -1) return true;
            if (a[i][0] > target) return false;
        }
        return false;
    }
Compare first element of every array and it is smaller than target, it binary searches this row
src/problems/medium/Searcha2DMatrixII.java