C version run 0ms


  • 0
    D
    void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
    int ** m = matrix;
    int n= matrixRowSize;
    for(int base = 0; base < n/2; ++base)
    {
    	for(int i = base; i < n - base - 1  ; ++i)
    	{
    		int tmp[4] = {0,0,0,0};
    		tmp[0] = m[base][i];
    		tmp[1] = m[i][n - 1 - base];
    		tmp[2] = m[n - 1 - base][n - 1 - i];
    		tmp[3] = m[n - 1 - i][base];
    		
    		m[base][i] = tmp[3];
    		m[i][n - 1 - base] = tmp[0];
    		m[n - 1 - base][n - 1 - i] = tmp[1];
    		m[n - 1 - i][base] = tmp[2];
    	}
    }
    

    }

    use a tmp 4 array


Log in to reply
 

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