class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
//设置左右边界,每次旋转最外圈
//需要4个变量指定上下左右边界
int left, right, up, down;
left = 0; //列0
right = matrix[0].size() - 1; //最右边列
up = 0; //行0
down = matrix.size() - 1; //最下方行
while(left < right && down > up){
for(int i = 0; i < right - left; i++){
int temp1 = matrix[up][left + i];
int temp2 = matrix[up + i][right];
int temp3 = matrix[down][right - i];
matrix[up][left + i] = matrix[down - i][left];
matrix[up + i][right] = temp1;
matrix[down][right - i] = temp2;
matrix[down - i][left] = temp3;
}
left++, right--, up++, down--;
}
}
};
06-06
4406
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-28
3733
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-02
5223
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)