public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix.length == 1) {
            for (int i=0; i<matrix[0].length; i++) {
                if (matrix[0][i] == target)
                    return true;
            }
            return false;
        }

        for (int i=1; i<matrix.length; i++) {
            if ( target > matrix[i-1][matrix[0].length-1] && target <= matrix[i][matrix[0].length-1] ) {
                int[] nums = new int[matrix[i].length];
                for (int j=0; j<matrix[i].length; j++) {
                    nums[j] = matrix[i][j];
                }
                return binarySearch(nums, target);
            } else if (target <= matrix[i-1][matrix[0].length-1]) {
                int[] nums = new int[matrix[i].length];
                for (int j=0; j<matrix[i-1].length; j++) {
                    nums[j] = matrix[i-1][j];
                }
                return binarySearch(nums, target);
            }
        }

        return false;
    }