第1种:
public int[][] rotate(int[][] a, int N){
int[][] b = new int[N][N];
for(int i = 0; i<N; i++){
for(int j =0; j< N; j++){
b[N-j-1][N-i-1] = a[i][N-1-j];
}
}
return b;
}
第2种:
public void rotate(int[][] a,int N){
int layer;
for(layer =0; layer<N/2; layer++){
int first = layer;
int last = N-1-layer;
int i;
for(i =layer;i<last;i++){
int offset = i-layer;
int top = a[first][i];
a[first][i] = a[last-offset][first];
a[last-offset][first] = a[last][last-offset];
a[last][last- offset] = a[i][last];
a[i][last] = top;
}
}
}