Description:
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Note:
- You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Example 1:
Example 2:
题意:将一个n维矩阵顺时针方向旋转90°;要求直接对此矩阵进行操作,不再额外的分配空间;
解法:对n维矩阵旋转90°相当于先将其转置后再对矩阵左右两边的元素进行交换即可;
例如:对于矩阵
Java