题解一:
翻转数组:先将数组沿右上-左下对角线翻转,再将数组上下翻转。
class Solution {public void rotate(int[][] matrix) {int n = matrix.length;for (int i = 0; i < n; i++) {//沿右上-左下对角线翻转for (int j = 0; j < n - i - 1; j++) {int temp = matrix[i][j];matrix[i][j] = matrix[n - j - 1][n - i - 1];matrix[n - j - 1][n - i - 1] = temp;}}for (int i = 0; i < n / 2; i++) {//沿上下翻转for (int j = 0; j < n; j++) {int temp = matrix[i][j];matrix[i][j] = matrix[n - i - 1][j];matrix[n - i - 1][j] = temp;}}}
}