Why is it runtime error with my C code? I can pss it on my VC++6.0


  • 0
    Z

    void setZeroes(int** matrix, int matrixRowSize, int matrixColSize) {

    if (matrix == NULL || matrixRowSize==0 || matrixColSize==0)     return;
    
    int i,j,row=0,col=0;
    for (i=0; i<matrixRowSize; i++){
        for (j=0; j<matrixColSize; j++){
            if (*(*matrix+i*matrixColSize+j)==0)    {	
    			if (i==0 && j==0)	{row = 1; col = 1; continue;}
                if (i == 0)     {row = 1;continue;}
                if (j == 0)     {col = 1;continue;}
    			*(*matrix+i*matrixColSize+0) = 0;
                *(*matrix+0*matrixColSize+j) = 0;
            }   
        }
    }
    
    for (i=1; i<matrixRowSize; i++)     
        if (*(*matrix+i*matrixColSize+0) == 0) {
            for (j=1; j<matrixColSize; j++)     *(*matrix+i*matrixColSize+j) = 0;
        }
    
    for (j=1; j<matrixColSize; j++)     
        if (*(*matrix+0*matrixColSize+j) == 0) {
            for (i=1; i<matrixColSize; i++)     *(*matrix+i*matrixColSize+j) = 0;
        } 
    
    if (row)    for (j=0; j<matrixColSize; j++)     *(*matrix+0*matrixColSize+j) = 0;
    if (col)    for (i=0; i<matrixRowSize; i++)     *(*matrix+i*matrixColSize+0) = 0;
    return;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.