LC 48. Rotate Image

Nilanjan Deb · April 6, 2020

This is my CPP solution.

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        int n = matrix.size();
        vector<vector<int>> ans;
        for(int j=0;j<n;j++){
            vector<int> row;
            for(int i=n-1;i>=0;i--){
                row.push_back(matrix[i][j]);
            }
            ans.push_back(row);
        }
        matrix = ans;
    }
};


Dicussion Forum