48.Rotate Image
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Rotate Image.
Memory Usage: 9.2 MB, less than 71.51% of C++ online submissions for Rotate Image.
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
vector<vector<int>> temp;
for (int i = 0; i < matrix.size(); i++)
{
vector<int> vec;
for (int j = matrix.size() - 1; j >= i; j--)
{
vec.push_back(matrix[j][i]);
}
for (int j = temp.size() - 1; j >= 0; j--)
{
vec.push_back(temp[j][i]);
}
temp.push_back(matrix[i]);
matrix[i] = vec;
}
}
};