给定一个NxN的矩阵,将图像顺时针旋转90度。
像素翻转
http://www.nowcoder.com/questionTerminal/17ab1e527c504df09a600e1af09d9a60
public int[][] transformImage(int[][] mat, int n) {
// write code here
int[][] result = new int[n][n];
int[] tmp = new int[n];
for (int i=0;i<n;i++){
for (int j=0;j<n;j++) {
tmp[j] = mat[n-j-1][i];
}
result[i] = tmp;
tmp = new int[n];
}
return result;
}
查看1道真题和解析
