C solutions for Rotate Image


  • 0
    X

    C solutions for Rotate Image
    '''
    int rotateCircle(int** p, int rowColSize, int cn, int stride)
    {
    int *pT;
    int *pR;
    int *pL;
    int *pB;
    int i;
    int tmpR,tmpB,tmpL;

    for(i = 0;i<rowColSize -1 ;i++ )
    {
        pT = &(p[cn][cn + i]) ;
        pR = &(p[cn + i][cn + rowColSize -1]); 
        pB = &(p[cn + rowColSize -1 ][cn + rowColSize -1 - i]); 
        pL = &(p[cn + rowColSize -1 - i][cn]) ;
        
        tmpR = *pR ;
        tmpB = *pB ;
        tmpL = *pL ;
        *pR = *pT;
        *pB = tmpR;
        *pL = tmpB;
        *pT = tmpL;       
    }
    return 0;
    

    }
    void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
    int i;
    int cn = 0;
    if(matrixRowSize != matrixColSize)
    return;
    if(matrixColSize <= 0 || matrix == NULL)
    return;

    for( i = matrixRowSize;i > 1; i -= 2)
    {
        
        rotateCircle(matrix, i, cn, matrixRowSize);
        cn++;
    }
    return;
    

    }
    '''


Log in to reply
 

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