public boolean searchMatrix(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0)
            return false;
        int up = 0;
        int down = matrix.length-1;
        while(up <= down ){
            int mid  = (up + down) /2;
            if(target > matrix[mid][0])
                up = mid+1;
            else if(target < matrix[mid][0])
                down = mid-1;
            else
                return true;
        }

        int index = down >0? down :0;
        up = 0;
        down = matrix[0].length-1;
        while(up <= down){
            int mid = (up+down)/2;
            if(matrix[index][mid] == target)
                return true;
            else if(matrix[index][mid] < target)
                up = mid+1;
            else
                down = mid -1;
        }
        return false;

    }