解题思路:先进行矩阵上下交换,接着对矩阵进行主对角线交换,就可以从上述左图变换为右图。
class Solution { public void rotate(int[][] matrix) { //上下交换 for(int i = 0 ; i<matrix.length/2;i++){ int[] temp = matrix[i]; matrix[i] = matrix[matrix.length-i-1]; matrix[matrix.length-i-1] =temp; } //对角交换 for(int i = 0 ; i<matrix.length;i++){ for(int j = i+1 ; j<matrix.length;j++){ int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } } }标签:matrix,--,矩阵,交换,int,上下,Leetcode From: https://blog.csdn.net/m0_46479109/article/details/140395836