leetcode48
Rotate Image
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
vector<vector<int>> temp;
int i = 0, j = 0;
vector<int> t;
for (; j < matrix.size(); ++j)
{
for (i = 0 ; i < matrix.size(); ++i)
{
t.push_back(matrix[i][j]);
}
temp.push_back(vector<int>(t.rbegin(), t.rend()));
t.clear();
}
matrix = temp;
}
};