一、题目内容

image.png

二、题解

解法1:

思路

找关系,a[j][n-i-1] = mat[i][j];

代码

  1. public class Solution {
  2. public int[][] rotateMatrix(int[][] mat, int n) {
  3. // write code here
  4. int[][] ans= new int[n][n];
  5. for(int i = 0;i<n;i++){
  6. for(int j = 0;j<n;j++){
  7. ans[j][n-i-1] = mat[i][j];
  8. }
  9. }
  10. return ans;
  11. }
  12. }