n x n
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int length = matrix[0].size();
for(int i = 0; i < length / 2; i ++){
swap(matrix[i],matrix[length - 1 - i]);
}
for(int i = 0; i < length; i ++){
for(int j = i + 1; j < length; j ++){
swap(matrix[i][j],matrix[j][i]);
}
}
}
};