标签:list etc reverse pre temp ever div 时间 toc
解法一:先以对角线为轴对调数字,在将每一行逆序即可。时间复杂度O(n^2)
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int i,j,n = matrix.size();
for(i = 0;i < n;i++)
{
for(j = i+1;j < n;j++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
reverse(matrix[i].begin(),matrix[i].end());
}
}
};
标签:list etc reverse pre temp ever div 时间 toc
原文地址:https://www.cnblogs.com/multhree/p/10415213.html