原题网址:https://leetcode.com/problems/rotate-image/
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
方法:直接旋转。
public class Solution {
public void rotate(int[][] matrix) {
for(int i=0; i<matrix.length/2; i++) {
for(int j=0; j<(matrix.length+1)/2; j++) {
int t = matrix[i][j];
matrix[i][j] = matrix[matrix.length-1-j][i];
matrix[matrix.length-1-j][i] = matrix[matrix.length-1-i][matrix.length-1-j];
matrix[matrix.length-1-i][matrix.length-1-j] = matrix[j][matrix.length-1-i];
matrix[j][matrix.length-1-i] = t;
}
}
}
}