Easy Self understand solution just transpose and reverse


#1
void transpose(vector<vector<int>>& matrix, int n){
         for(int i=0; i<n; i++){
             for(int j=i; j<n; j++){
                 int temp = matrix[i][j];
                 matrix[i][j] = matrix[j][i];
                 matrix[j][i] = temp;
             }
         }
     }
    
    void reverse(vector<vector<int>> & matrix, int n){
        for(int i=0; i<n; i++){
            for(int j=0; j<n/2; j++){
                int temp = matrix[i][j];
                matrix[i][j] = matrix[i][n-j-1];
                matrix[i][n-j-1] = temp;
            }
        }
    }

void Solution::rotate(vector<vector<int> > &matrix) {
        int n = matrix.size(); 
        transpose(matrix,n);
        reverse(matrix,n);
}