import java.util.*;
//经过分析可以得知矩阵经过两步就可以旋转90度
//1.先进性上下翻转
//2.再进行置换
public class Solution {
public int[][] rotateMatrix(int[][] mat, int n) {
// write code here
int top = 0;
int tail = n - 1;
for (; top < tail; top++, tail--){ //先进性上下翻转
for (int i = 0; i < n; i++){
mat[top][i] = mat[top][i] ^ mat[tail][i];
mat[tail][i] = mat[top][i] ^ mat[tail][i];
mat[top][i] = mat[top][i] ^ mat[tail][i];
}
}
for (int i = 0; i < n; i++){
for (int j = n - 1; j > i; j--){
mat[i][j] = mat[i][j] ^ mat[j][i];
mat[j][i] = mat[i][j] ^ mat[j][i];
mat[i][j] = mat[i][j] ^ mat[j][i];
}
}
return mat;
}
}