My c solution by recusion, 0ms


  • 0
    W
    // desc : rotate the up edge of inner matrix recusively
    void rotateEdge(int** matrix, int begin, int end, int size) {
        if (begin >= end) return;
        for (int i = begin; i < end; ++i) {
            int key = matrix[begin][i];
            matrix[begin][i] = matrix[size-i][begin];
            matrix[size-i][begin] = matrix[size-begin][size-i];
            matrix[size-begin][size-i] = matrix[i][size-begin];
            matrix[i][size-begin] = key;
        }
        rotateEdge(matrix, begin+1, end-1, size);
        return;
    }
    
    void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
        rotateEdge(matrix, 0, matrixRowSize-1, matrixRowSize-1);
        return;
    }

Log in to reply
 

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