描述
有一个NxN整数矩阵,请编写一个算法,将矩阵顺时针旋转90度。
给定一个NxN的矩阵,和矩阵的阶数N,请返回旋转后的NxN矩阵。
数据范围:0 < n < 3000<n<300,矩阵中的值满足 0 \le val \le 10000≤val≤1000
import java.util.*;
public class Solution {
public int[][] rotateMatrix(int[][] mat, int n) {
// write code here
int[][] res = new int[n][n];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
res[j][n - 1 - i] = mat[i][j];
}
}
return res;
}
}