class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
//旋转 相对位置变化 - 翻转
//DETRAIL 转置+对称翻转
//T
int n = matrix.size();
int tmp;
for(int i = 0; i < n; i++){
for(int j = i; j < n; j++){
tmp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = tmp;
}
}
//翻转
int lim = n/2;
for(int i = 0; i < n; i++){
for(int j = 0; j < lim; j++){
tmp = matrix[i][j];
matrix[i][j] = matrix[i][n-1-j];
matrix[i][n-1-j] = tmp;
}
}
}
};
↓ 下面的太麻烦了,再做的时候都忘了解法,懒得看~
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n = matrix.size();
// up down
for(int i = 0; i < n/2; i++)
for(int j = 0; j < n; j++)
{
int tmp = matrix[i][j];
matrix[i][j] = matrix[n-i-1][j];
matrix[n-i-1][j] = tmp;
}
// zhu
for(int i = 0; i < n ; i++)
for(int j = 0; j < i; j++)
{
int tmp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = tmp;
}
}
};
文章来源:https://www.toymoban.com/news/detail-740281.html
文章来源地址https://www.toymoban.com/news/detail-740281.html
到了这里,关于*LEEDCODE 48旋转图像的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!