Clean c++ solution


  • 0
    void rotate(vector<vector<int>>& matrix) {
        rotate(matrix, 0, matrix.size() - 1);
    }
    
    void rotate(vector<vector<int>>& matrix, int start, int n) {
        if (start >= n)
            return;
        for (int i = 0; i < n - start; i++) {
            int temp = matrix[start][start + i];
            matrix[start][start + i] = matrix[n - i][start];
            matrix[n - i][start] = matrix[n][n - i];
            matrix[n][n - i] = matrix[start + i][n];
            matrix[start + i][n] = temp;
        }
        rotate(matrix, start + 1, n - 1);
    }
    

Log in to reply
 

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