- We can take 1 more 2D matrix and perform the operation
- But this is not allowed.
- Clockwise 90deg rotation
- Reverse the matrix.
- Transpose the matrix.
class Solution {
public:
void rotate(vector<vector<int>>& matrix)
{
int n = matrix.size(),m = matrix[0].size();
reverse(matrix.begin(), matrix.end());
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < m; j++)
swap(matrix[i][j], matrix[j][i]);
}
}
};